C
Carlos1815
This may seem like an easy question considering all the difficult
questions I've been peppering everyone with, but it confounds me!
I have a rather large set of code that needs to be used for each topic
I have (18 of them!). Don't ask why I did it that way, it kind of
snowballed. Now, I can achieve the end result I'm looking for if I do
it the long way. Let me illustrate:
********************************************************************
If Me.RecordSource = "Topic1" Then
Lots of code...
Lots of code...
Lots of code...
Lots of code...
End if
If Me.RecordSource = "Topic2" Then
Lots of code...
Lots of code...
Lots of code...
Lots of code...
End if
********************************************************************
I'd rather not have to keep copying and pasting so much code 18 times,
and I thought I could use a variable; something like this:
Dim i as Integer
Do while i = 1 to 18
If Me.RecordSource = "Topic" & i Then
Lots of code...
Lots of code...
Lots of code...
Lots of code...
End if
Loop
I tried using that above code, though instead of "i = 1 to 18", I used
"i < 19" and that made Access very, very angry at me; so I set
everything back and didn't even try the other way. Can anyone give me
the correct way to code that? It would help greatly since I have a
lot of sections where I needed to repeat code multiple times and this
would streamline my VB immensely. Thanks in advance!
Carlos
questions I've been peppering everyone with, but it confounds me!
I have a rather large set of code that needs to be used for each topic
I have (18 of them!). Don't ask why I did it that way, it kind of
snowballed. Now, I can achieve the end result I'm looking for if I do
it the long way. Let me illustrate:
********************************************************************
If Me.RecordSource = "Topic1" Then
Lots of code...
Lots of code...
Lots of code...
Lots of code...
End if
If Me.RecordSource = "Topic2" Then
Lots of code...
Lots of code...
Lots of code...
Lots of code...
End if
********************************************************************
I'd rather not have to keep copying and pasting so much code 18 times,
and I thought I could use a variable; something like this:
Dim i as Integer
Do while i = 1 to 18
If Me.RecordSource = "Topic" & i Then
Lots of code...
Lots of code...
Lots of code...
Lots of code...
End if
Loop
I tried using that above code, though instead of "i = 1 to 18", I used
"i < 19" and that made Access very, very angry at me; so I set
everything back and didn't even try the other way. Can anyone give me
the correct way to code that? It would help greatly since I have a
lot of sections where I needed to repeat code multiple times and this
would streamline my VB immensely. Thanks in advance!
Carlos