Selecting entry form from list box?

J

Johny

Trying to choose a unique data entry form from a drop down list of 2 choices
(male/female). Know that I need some VB code to make this happen but can't
find any info on what the proper syntax might be? Assuming that I would
choose the "code builder" of the "on change" selection from the property
sheet?

Any help or links to info would be greatly appriciated.

Johny
 
D

Dirk Goldgar

Johny said:
Trying to choose a unique data entry form from a drop down list of 2
choices (male/female). Know that I need some VB code to make this
happen but can't find any info on what the proper syntax might be?
Assuming that I would choose the "code builder" of the "on change"
selection from the property sheet?

Any help or links to info would be greatly appriciated.

Johny

The After Update event is actually better than the Change event
(because, if the user types into the combo box instead of using the
mouse, the Change event fires with each keystroke, while the AfterUpdate
event fires only when the choice is complete, no matter how it is done).

You haven't given any details, but maybe the following example of a
complete event procedure would be helpful:

'----- start of example code -----
Private Sub cboSex_AfterUpdate()

Dim strFormName As String

Select Case Me!cboSex
Case "M"
strFormName = "frmDataEntryMale"
Case "F"
strFormName = "frmDataEntryFemale"
End Select

' Make sure *something* was chosen ...
If Len(strFormName) = 0 Then
MsgBox "You must choose 'male' or 'female' to proceed."
Else
' Open the appropriate form.
DoCmd.OpenForm strFormName
End If

End Sub
'----- end of example code -----
 
J

Johny

Sorry for the lack of spacifics.

It's actually a combo box (named gender) placed on a form called "main page"
used to collect info from our talent. Some personal stats are different for
male and female so I have created diferent forms (named "male personal info"
and "female personal info")to be called from the "main page". I have
defined the value of male as 1 and female as 2.

Using Access 2003. My choices were expression builder, macro builder or
code builder for customizing the after update argument. Chose code builder.

Can I modify your code to accomplish this task? Is there a resource that
would give me an idea of syntax and usage for VB code? The VB help in
Access was all but useless. I couldn't even devise a question that would
give me some help on opening a form from within another form.

Thank you for your quick reply and any future help or suggestions.

Johny
 
D

Dirk Goldgar

Johny said:
Sorry for the lack of spacifics.

It's actually a combo box (named gender) placed on a form called
"main page" used to collect info from our talent. Some personal
stats are different for male and female so I have created diferent
forms (named "male personal info" and "female personal info")to be
called from the "main page". I have defined the value of male as 1
and female as 2.

Using Access 2003. My choices were expression builder, macro builder
or code builder for customizing the after update argument. Chose
code builder.

Can I modify your code to accomplish this task? Is there a resource
that would give me an idea of syntax and usage for VB code? The VB
help in Access was all but useless. I couldn't even devise a
question that would give me some help on opening a form from within
another form.

Thank you for your quick reply and any future help or suggestions.

Code builder was the right choice. As I mentioned, I think this should
be used with the After Update event, not the Change event as you had
originally planned. So if you pick the code builder you'll see a
procedure shell that looks like this:

Private Sub Gender_AfterUpdate()

End Sub

Let's take the example code I posted and substitute the names and values
you've now given me:

'----- start of revised code -----
Private Sub Gender_AfterUpdate()

Dim strFormName As String

Select Case Me!Gender
Case 1
strFormName = "Male Personal Info"
Case 2
strFormName = "Female Personal Info"
End Select

' Make sure *something* was chosen ...
If Len(strFormName) = 0 Then
MsgBox "You must choose 'male' or 'female' to proceed."
Else
' Open the appropriate form.
DoCmd.OpenForm strFormName
End If

End Sub
'----- end of revised code -----

See what happens if you copy and paste that in place of the empty shell
that the code builder left you with.
 
J

Johny

Finally got it to work. Found a Visual Basic tutorial which helped me
realize I gave you incorrect info. I have been struggling with this problem
for a couple of days. I no longer had Male and Female set to 1 and 2, was
now using a combo box and had used the on update argument. The brain took
pieces from differant atempts and combined them. Male was never 1 so Case 1
was never true. Of course the sub always defaulted to no entry. Changed to
Case "Male" and it worked like a dream.

Thanks again for all the help!

Johny
 
N

Nicharkorn

ºéÒầ¤ì
Dirk Goldgar said:
The After Update event is actually better than the Change event
(because, if the user types into the combo box instead of using the
mouse, the Change event fires with each keystroke, while the AfterUpdate
event fires only when the choice is complete, no matter how it is done).

You haven't given any details, but maybe the following example of a
complete event procedure would be helpful:

'----- start of example code -----
Private Sub cboSex_AfterUpdate()

Dim strFormName As String

Select Case Me!cboSex
Case "M"
strFormName = "frmDataEntryMale"
Case "F"
strFormName = "frmDataEntryFemale"
End Select

' Make sure *something* was chosen ...
If Len(strFormName) = 0 Then
MsgBox "You must choose 'male' or 'female' to proceed."
Else
' Open the appropriate form.
DoCmd.OpenForm strFormName
End If

End Sub
'----- end of example code -----

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Top