VBA for opening different forms

mara

Registered User.
Local time
Today, 23:31
Joined
Sep 20, 2011
Messages
15
Hi there,

I am creating a HR database with forms such as Incident, Investigation, Hazard, Non conformance, appraisal ect. I need queries so that each report can be somehow found without having to go through all the data. I have created a form called "searchcentre" where I have placed unmanaged Combo boxes and text boxes so to help with the queries, ie Name, date, location. This all (to my knowledge is working fine)

Seeing as I have multiple forms, I have created a Combo box containing the form names for the user to select, and would like to create a VBA code for a button placed at the bottom so If Incident report, then open "incident report" If Hazard, then open hazard" ect.
I am only new to VBA and am a little unsure on how to do this, and every thing I try doesn't seem to work.

Any suggestions would be helpful. Thankyou
 
The code is actually pretty simple presuming the combo has the actual name:

DoCmd.OpenForm Me.ComboName

with any of the other appropriate arguments specified.
 
I just built some security stuff that used the Access system table MSysNameMap. You might look into building a link table that has the human-understandable form name that uses the actual form name from MSysNameMap to pass to the code that opens the form. I'm solving a different problem (deciding to not open the form or to open it) but it's the same process.
 
Hmmm, I am not sure whether that's the code I needot not. Every code seems to have no effect, or comes up with a debugging error.

The code I'd originally beentrying was similar to:

If Me.combofrmName = "Incident Report" then docmd.Openform(frmIncidentQuery)
And If Me.combofrmName = "Hazard observation" hen docmd.Openform(frmHazardQuery)

And so on for eah form befoe ending sub. So that I only had one button, and one combo box. I have tried it with both entering the details in a unmanaged Combo box that looks up the values froma tabe I created and entering the details into the combo box manually.

Still no luck. Any suggstions?
Thankou
 
This would be:

If Me.combofrmName = "Incident Report" then docmd.Openform "frmIncidentQuery"

If you go that way, you'd want to use Select/Case or ElseIf to avoid testing every option even after one is found.
 

Users who are viewing this thread

Back
Top Bottom