Zack Barresse
MrExcel MVP
- Joined
- Dec 9, 2003
- Messages
- 10,881
- Office Version
- 365
- 2010
- Platform
- Windows
- Mobile
- Web
Hi all,
I'm looking for the functionality of the Rept() function in Excel to be used in Access. Is there any native function for this?
Let me explain my problem a little bit, maybe it's not the best way to go about it, plus the background would help I think.
Situation:
Newly created Access database to house monthly meter readings with report capabilities.
Field structure:
fldReadingID (primary key), fldReadingDate, fldReadingMeter, fldReadingValueStart, fldReadingValuePrevious
Problem:
Everything is working except my report. I have all the values in as needed but I have a calculated field with the following formula ...
The "999999999" is the problem, this is for meter turnover. So if I have a start reading value of 998 and an end reading value of 25 the difference (formulated) value is 27. The problem lies where there will be a varying length for the meters (of values to the left of the decimal); some will have 3 numbers, some will have 7 numbers and a decimal, some will have 10 values. So my solution was a formula such as...
This was to say that if the start number (txtstart) was greater than the end number than we could safely assume that the meter had turned over and started at 0 again. So in essence what the Rept() function was to be used for was this logic:
Start reading: 998
Take 1000 - 998, then add the end reading. To get the 1000 I was thinking about using a Rept()-type function to get the [variable] length, add one, etc.
Hope this makes sense; if not let me know what you need. Thanks.
I'm looking for the functionality of the Rept() function in Excel to be used in Access. Is there any native function for this?
Let me explain my problem a little bit, maybe it's not the best way to go about it, plus the background would help I think.
Situation:
Newly created Access database to house monthly meter readings with report capabilities.
Field structure:
fldReadingID (primary key), fldReadingDate, fldReadingMeter, fldReadingValueStart, fldReadingValuePrevious
Problem:
Everything is working except my report. I have all the values in as needed but I have a calculated field with the following formula ...
Code:
IIf([txtstart]<[txtend],[txtend]-[txtstart],999999999-([txtstart]-[txtend]))
The "999999999" is the problem, this is for meter turnover. So if I have a start reading value of 998 and an end reading value of 25 the difference (formulated) value is 27. The problem lies where there will be a varying length for the meters (of values to the left of the decimal); some will have 3 numbers, some will have 7 numbers and a decimal, some will have 10 values. So my solution was a formula such as...
Code:
=IIf([txtstart]<[txtend],[txtend]-[txtstart],(1+(Rept(9,Len([txtstart])))-[txtstart])+[txtend])
This was to say that if the start number (txtstart) was greater than the end number than we could safely assume that the meter had turned over and started at 0 again. So in essence what the Rept() function was to be used for was this logic:
Start reading: 998
Take 1000 - 998, then add the end reading. To get the 1000 I was thinking about using a Rept()-type function to get the [variable] length, add one, etc.
Hope this makes sense; if not let me know what you need. Thanks.