Using integers in variable names.


B

BrianDP

Hello All- Seems like the Eval() function would help here somehow, but I can't seem to get it to work so I thought I'd explain it like this:

I would like to take these statements, and instead of

:
: If (Nz(x0Receipt) > 0) And (Len(x0Callback) = 0) Then
: MsgBox "Entry on Line 1 doesn't have an associated Receipt line."
: End If
:
: If (Nz(x1Receipt) > 0) And (Len(x1Callback) = 0) Then
: MsgBox "Entry on Line 2 doesn't have an associated Receipt line."
: End If
: .
: .
: .
:
: If (Nz(x9Receipt) > 0) And (Len(x9Callback) = 0) Then
: MsgBox "Entry on Line 10 doesn't have an associated Receipt line."
: End If
:


I would like something like:


for ZZ = 0 to 9

if (nz(xZZReceipt) > 0) and (Len(xZZCallback) = 0) then
msgbox "The " & dhOrd(ZZ+1) & " Line doen't have an associated Receipt Line"
end if

next ZZ
 
Ad

Advertisements

A

Access Developer

Are you simply repeating to allow more than one instance of something to be
entered on that form in separate fields? If so, rethink your design, and
consider using a "continuous forms view" form displaying multiple records.

If not, (that is, if there is some compelling reason to re-implement
displaying of multiple records on one form then look at using the type of
reference to an object in a collection where you specifiy the name in text
form, but instead of the literal name surrounded by quotes, refer to a
variable containing the control name, and recalculate the variable
containing the control name, using the index value of the loop, on each
pass.
 
B

BrianDP

Larry,

Thanks for your reply. I've seen the stuff You've been posting for years and I've always found it to be top notch.

Well, the reason I'm repeating, and have this odd representation of data infields on a form to match whats going on in the subform, is in response toa request from the client. I thought it could have been done better by just having them enter the data into the subform, but they wanted it done this way, where the line items are displayed on the subform, and then the userwould key into fields out to the right, lined up next to the fields on thesubform. What a pain in the rump I'll tell you to keep that all synched up. Well, now that I have it working, what a kludge to get that to work, I'd like to tidy it up a bit, and one way I could see to do that would be to eliminate that large stanza in my code where I repeat that line over and over again with incrementing integers, with a for next loop, or a do while orsomething and reuse the code.

I gather from your response, and from my past experience, that this is NOT possible.

Since the code is already written, I'll just leave it. It's just a real problem though whenever I make a change to the workings of this thing as I morph it along, I have to apply any change 10 times!

Thanks Larry.

-Brian
 
A

Access Developer

Did you look at whether my second suggestion might work for you? Referring
to Controls is, in fact, referring to the Controls in the Form's collection
of controls and one approach to referring to objects in a collection is to
use the name in text form.

Yep, I can hark back to a few times when the client was adamant about some
not-very-good idea and I had to remind myself that "the customer isn't
always right, but they are the one who's paying the bill". And, sometimes it
led to an interesting development experience.

--
Larry Linson
Microsoft Office Access MVP
Co-Author, Microsoft Access Small Business Solutions, Wiley 2010

Larry,

Thanks for your reply. I've seen the stuff You've been posting for years
and I've always found it to be top notch.

Well, the reason I'm repeating, and have this odd representation of data in
fields on a form to match whats going on in the subform, is in response to a
request from the client. I thought it could have been done better by just
having them enter the data into the subform, but they wanted it done this
way, where the line items are displayed on the subform, and then the user
would key into fields out to the right, lined up next to the fields on the
subform. What a pain in the rump I'll tell you to keep that all synched up.
Well, now that I have it working, what a kludge to get that to work, I'd
like to tidy it up a bit, and one way I could see to do that would be to
eliminate that large stanza in my code where I repeat that line over and
over again with incrementing integers, with a for next loop, or a do while
or something and reuse the code.

I gather from your response, and from my past experience, that this is NOT
possible.

Since the code is already written, I'll just leave it. It's just a real
problem though whenever I make a change to the workings of this thing as I
morph it along, I have to apply any change 10 times!

Thanks Larry.

-Brian
 
D

Douglas J Steele

Just in case Larry's being too cryptic for you,

For ZZ = 0 To 9

If (Nz(Me.Controls("x" & ZZ & "Receipt") > 0) and (Len(Me.Controls("x" &
ZZ " & "Callback") = 0) Then
MsgBox "The " & dhOrd(ZZ+1) & " Line doesn't have an associated Receipt
Line"
End If

Next ZZ

"Access Developer" wrote in message

Did you look at whether my second suggestion might work for you? Referring
to Controls is, in fact, referring to the Controls in the Form's collection
of controls and one approach to referring to objects in a collection is to
use the name in text form.

Yep, I can hark back to a few times when the client was adamant about some
not-very-good idea and I had to remind myself that "the customer isn't
always right, but they are the one who's paying the bill". And, sometimes it
led to an interesting development experience.

--
Larry Linson
Microsoft Office Access MVP
Co-Author, Microsoft Access Small Business Solutions, Wiley 2010

Larry,

Thanks for your reply. I've seen the stuff You've been posting for years
and I've always found it to be top notch.

Well, the reason I'm repeating, and have this odd representation of data in
fields on a form to match whats going on in the subform, is in response to a
request from the client. I thought it could have been done better by just
having them enter the data into the subform, but they wanted it done this
way, where the line items are displayed on the subform, and then the user
would key into fields out to the right, lined up next to the fields on the
subform. What a pain in the rump I'll tell you to keep that all synched up.
Well, now that I have it working, what a kludge to get that to work, I'd
like to tidy it up a bit, and one way I could see to do that would be to
eliminate that large stanza in my code where I repeat that line over and
over again with incrementing integers, with a for next loop, or a do while
or something and reuse the code.

I gather from your response, and from my past experience, that this is NOT
possible.

Since the code is already written, I'll just leave it. It's just a real
problem though whenever I make a change to the workings of this thing as I
morph it along, I have to apply any change 10 times!

Thanks Larry.

-Brian
 
A

Access Developer

Douglas J Steele said:
Just in case Larry's being too cryptic for you,
Hmm. You mean not everyone is fluent in Cryptic? <GRIN>

I'm sorry I was obtuse and thanks, Doug, for picking up the thread.

Larry
 
Ad

Advertisements

B

BrianDP

Doug,

Hey! That might be what I'm looking for! Sorry Larry for not beign able to decipher what you meant. Yes. I'll try writing it like that. I think it might work!

-B
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top