Open different forms depending on choice

kbrooks

Still learning
Local time
Today, 12:11
Joined
May 15, 2001
Messages
202
I have a form and just figured out how to get a pop-up form to open if a certain answer is entered into a field. But so far I've only had one option per field that needed a pop-up form.

I now have a field (combo box) called OccurrenceCategory that the user can pick from one of several options.

If they answer "A", I want the "A" form to pop up. If they answer "B", I want the "B" form to pop up. Etc.

I have all the pop-up forms created and ready to go, I just need help with the macro. I tried putting several OpenForm commands, each with a different where statement for each different answer, but it opens all possible pop-up forms no matter which answer you choose. I also tried entering it into the Condition column in the macro, but I got a visual basic error when I tried to test it.

Thanks for any help you can give me!
 
What you need is a SELECT CASE statement like this to automatically change the value of MyDocName when the button is clicked:

Dim MyDocName as String

Select Case Me.OccurrenceCategory
Case = "A"
MyDocName = "TheNameOfTheAForm"
Case = "B"
MyDocName = "TheNameOfTheBForm"
Case = "C"
MyDocName = "TheNameOfTheCForm"
Case Else
Msgbox "Please select an option from the combo box",0,"Application Title"
Exit sub
End Select
'open the form represented by MyDocName
Docmd.OpenForm MyDocName,acNormal

Hope that helps

Ian
 
Well I understand what you're saying, but I'm not sure exactly where to enter this select statement. Within the macro?

Sorry, I'm a bit dense today!
 
You could try using conditions in your macro. [forms]![name of form]![name of field]="A" would run that particular action (like open a popupform) only if that condition is true. You could do a separate condition for each answer you want, and then attach it to something like the 'after update' property of the field.
 
Put a button on your form to open any form, it doesn't really matter. Go behind the form by opening the code(click the small button next to the OnClick event - note you must put the cursor in the property field to see the buttons). You will see the buttons code has this bit:

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "CostCreationTable"
DoCmd.OpenForm stDocName, , , stLinkCriteria

replace it with the code I gave you above.

sorry it's not a macro answer, but I don't do alot with them..
HTH
 

Users who are viewing this thread

Back
Top Bottom