Help with code

  • Thread starter gmazza via AccessMonster.com
  • Start date
G

gmazza via AccessMonster.com

Hi there,
I need some help so I don't have to repeat my code a ton of times.

I have 20 Visit buttons on my form labelled Visit 1, Visit 2, etc. When the
user chooses a visit, the number gets stored in a text box. So they choose
Visit 2, the number 2 gets stored in a textbox.
Once they click any visit button, a Visit form opens and On Open I am doing
the following:
I am setting the declared integer VisitNo = to the text box, so 2 in this
case.
I have 20 VisitFlags, declared as integers, named VisitFlag1, VisitFlag2, etc.


I have a control form where the user decides which visits they want certain
info showing on the actual Visit form by clicking a check box for which visit
they want.
I open a recordset of the control form to see which visit the user chose.
In my recordset I do something like this:
If fld.Name = "Visit2" Then
If fld.Value = False Then
VisitFlag2 = 0
Else
VisitFlag2 = 2
End If
End If

So then, from the If statement above, I will be able to see if VisitFlag2 = 0,

meaning it wasn't chosen in the control form, or it equals 2, meaning it was
chosen.
So now I need to see if the VisitNo, which is at 2 because they clicked the
Visit 2 button, equals the Visit2Flag but I can't just use the word
Visit2Flag because there are 20 Flags, I just want to say something like:
If VisitNo = VisitFlag & VisitNo Then
blah blah

meaning:
If 2 = (the value of VisitFlag2)

Hope this makes sense!
Thanks for everyones help!
 
J

Jeff Boyce

Wow! That must take up a lot of room on the form!

And that must require a lot of "maintenance" whenever the number of visits
changes!

(hint: this is NOT the preferred approach)

You've described your solution (multiple command buttons, flags, ...), but
not your problem.

If you'll provide a specific description of what business issue you are
trying to address, folks here may be able to offer ideas that could simplify
your user interface.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
K

Klatuu

Your description is somewhat confusing, but if I understand, you want to
click on one of 20 command buttons and pass the value of the selected button
to your visit form when you open it.

If I understand correctly, I would suggest you put your command buttons in a
option group and assign each the Option value corresponding to the vist
number. So the first button labled "Visit 1" would have an option value of
1, "Visit 2" would have an option value of 2, etc.

Then use the After Update event of the option group to open your visit form.
Pass the value of the button using the OpenArgs argument of the OpenForm
method.

Docmd.OpenForm "frmVisit", , , , , , Me.opgVisitNumber

Now, to populate the text box in the Visit form, use the Load event, not the
Open event of the form.

Me.txtVisitNumber = Nz(Me.OpenArgs)
 
G

gmazza via AccessMonster.com

Sorry for the confusion, I have a control form with certain fields that user
can choose which Visit they would like those fields to show up on by clicking
an option pertianing to a specific visit.
So for a specific field, they choose Visit 1 and 5 to have that field on, for
example.

So on my patient form, the user clicks the Visit 5 button.
It opens the visit form, my code looks to the control table to see what
fields had the Visit5 option clicked, then displays those specific fields.

I have 20 Integers I declared in my On Open event, named VisitFlag1,
VisitFlag2 etc
I have a text field, VisitNo, that grabs the visit number they clicked on the
Patient form.

I just want to compare the 2 by saying something like:

If VisitNo = VisitFlag & VisitNo
Then
blah

I can't do the If statement. Instead I have to do this:
If VisitNo = VisitFlag1

for each Visit. There has to be a way to write that if statement, it doesn't
like the concatenation.
Hope that helps, thanks for your reply.


Your description is somewhat confusing, but if I understand, you want to
click on one of 20 command buttons and pass the value of the selected button
to your visit form when you open it.

If I understand correctly, I would suggest you put your command buttons in a
option group and assign each the Option value corresponding to the vist
number. So the first button labled "Visit 1" would have an option value of
1, "Visit 2" would have an option value of 2, etc.

Then use the After Update event of the option group to open your visit form.
Pass the value of the button using the OpenArgs argument of the OpenForm
method.

Docmd.OpenForm "frmVisit", , , , , , Me.opgVisitNumber

Now, to populate the text box in the Visit form, use the Load event, not the
Open event of the form.

Me.txtVisitNumber = Nz(Me.OpenArgs)
Hi there,
I need some help so I don't have to repeat my code a ton of times.
[quoted text clipped - 36 lines]
Hope this makes sense!
Thanks for everyones help!
 
G

gmazza via AccessMonster.com

It actually doesn't take up much room on the form if you seen it.
The maintenance isn't bad either, they choose the number of visits when they
start a new trial and then thats how many show up on the form.
I only want 1 Visit form though, and want info showing up depending on what
they chose in the control form.

My database works perfect, but my problem is there is a lot of code on my
Visit form and I was wondering if there was a way I could write an IF
statement and compare what VisitNo it is, to the flag they chose in the
control form.



Jeff said:
Wow! That must take up a lot of room on the form!

And that must require a lot of "maintenance" whenever the number of visits
changes!

(hint: this is NOT the preferred approach)

You've described your solution (multiple command buttons, flags, ...), but
not your problem.

If you'll provide a specific description of what business issue you are
trying to address, folks here may be able to offer ideas that could simplify
your user interface.

Regards

Jeff Boyce
Microsoft Office/Access MVP
Hi there,
I need some help so I don't have to repeat my code a ton of times.
[quoted text clipped - 44 lines]
Hope this makes sense!
Thanks for everyones help!
 
J

Jeff Boyce

I don't have experience approaching this from the technique you've
implemented. Perhaps one of the other newsgroup readers has...

Regards

Jeff Boyce
Microsoft Office/Access MVP

gmazza via AccessMonster.com said:
It actually doesn't take up much room on the form if you seen it.
The maintenance isn't bad either, they choose the number of visits when
they
start a new trial and then thats how many show up on the form.
I only want 1 Visit form though, and want info showing up depending on
what
they chose in the control form.

My database works perfect, but my problem is there is a lot of code on my
Visit form and I was wondering if there was a way I could write an IF
statement and compare what VisitNo it is, to the flag they chose in the
control form.



Jeff said:
Wow! That must take up a lot of room on the form!

And that must require a lot of "maintenance" whenever the number of visits
changes!

(hint: this is NOT the preferred approach)

You've described your solution (multiple command buttons, flags, ...), but
not your problem.

If you'll provide a specific description of what business issue you are
trying to address, folks here may be able to offer ideas that could
simplify
your user interface.

Regards

Jeff Boyce
Microsoft Office/Access MVP
Hi there,
I need some help so I don't have to repeat my code a ton of times.
[quoted text clipped - 44 lines]
Hope this makes sense!
Thanks for everyones help!
 
S

Steve Sanford

I am also confused, but looking at your examples, I think you want to loop
thru the controls instead of writing discrete IF() statements.

So, for this example

If fld.Name = "Visit2" Then
If fld.Value = False Then
VisitFlag2 = 0
Else
VisitFlag2 = 2
End If
End If


you could try: (***untested**)


'k = kounter
Dim k As Integer

For k = 1 To 20
If fld.Name = "Visit" & k Then
Me("VisitFlag" & k) = Abs(fld.Value) * k
End If
Next 'k


And for this example, you could try:


For k = 1 To 20
If Me.VisitNo = Me("VisitFlag" & k) Then
'blah blah
End If
Next


*** See: http://www.mvps.org/access/forms/frm0003.htm


HTH
 
G

gmazza via AccessMonster.com

Exactly what I was looking for, thanks for your help Steve! Implemented and
working!!

Steve said:
I am also confused, but looking at your examples, I think you want to loop
thru the controls instead of writing discrete IF() statements.

So, for this example

If fld.Name = "Visit2" Then
If fld.Value = False Then
VisitFlag2 = 0
Else
VisitFlag2 = 2
End If
End If

you could try: (***untested**)

'k = kounter
Dim k As Integer

For k = 1 To 20
If fld.Name = "Visit" & k Then
Me("VisitFlag" & k) = Abs(fld.Value) * k
End If
Next 'k

And for this example, you could try:

For k = 1 To 20
If Me.VisitNo = Me("VisitFlag" & k) Then
'blah blah
End If
Next

*** See: http://www.mvps.org/access/forms/frm0003.htm

HTH
Hi there,
I need some help so I don't have to repeat my code a ton of times.
[quoted text clipped - 36 lines]
Hope this makes sense!
Thanks for everyones help!
 
S

Steve Sanford

Excelent....

--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


gmazza via AccessMonster.com said:
Exactly what I was looking for, thanks for your help Steve! Implemented and
working!!

Steve said:
I am also confused, but looking at your examples, I think you want to loop
thru the controls instead of writing discrete IF() statements.

So, for this example

If fld.Name = "Visit2" Then
If fld.Value = False Then
VisitFlag2 = 0
Else
VisitFlag2 = 2
End If
End If

you could try: (***untested**)

'k = kounter
Dim k As Integer

For k = 1 To 20
If fld.Name = "Visit" & k Then
Me("VisitFlag" & k) = Abs(fld.Value) * k
End If
Next 'k

And for this example, you could try:

For k = 1 To 20
If Me.VisitNo = Me("VisitFlag" & k) Then
'blah blah
End If
Next

*** See: http://www.mvps.org/access/forms/frm0003.htm

HTH
Hi there,
I need some help so I don't have to repeat my code a ton of times.
[quoted text clipped - 36 lines]
Hope this makes sense!
Thanks for everyones help!
 

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

Top