Combo box to pull up a form?

afs24

Board Regular
Joined
Sep 26, 2002
Messages
237
Does anyone know how to use a combo box to pull up a form. I have a bunch of different forms that I use and continually adding new ones. I would like to have a combo box so that the user can just pull up the company name and that companys form will pop up. Can anyone provide me with an example of how to do this?
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hey Afs24

To do this you need to do two things. One is to get a list of your forms into a combobox control, and then to open one you have selected from that list.

First things first, the combobox control.

Add this SQL string to the recordsource:

SELECT name from MSysobjects where (MSysobjects.Type = -32768)
ORDER BY name

This will give your combobox a list of all the forms in your database.

Now, the user can choose a form, but you now need to use an event that will open the form. You will most likely use a click event. To do this you must add a commandButton to your form and add this code to the _Click event...

Sub CommandButton<numHere>_Click
Dim strName As String

strName = Me.Combo<numHere>.value
DoCmd.OpenForm strName

End Sub

That should do the trick.

anvil19 :p
 
Upvote 0
Hello, thanks for the help.

My combo box is working but when I created a comand button and copied the code in the click event I got this error message:

---------------------------
Microsoft Visual Basic
---------------------------
Compile error:

Method or data member not found
---------------------------
OK Help
---------------------------

I'm not sure what to do from here?
 
Upvote 0
Has anyone had a chance to review my last post regarding the error message? I was able to complete the form but I'm not sure what happened when I pasted the code in the click event? Thanks
 
Upvote 0
Hi afs24

Just add the number of the combobox to the line :

strName = Me.Combo.value , just after the Combo bit i.e.

strName = Me.ComboNumber Here.value

anvil19
:eek:
 
Upvote 0
Thanks!

I'm still getting the same error message. When you say number is this what you mean?

Private Sub Command2_Click()
Dim strName As String

strName = Me.Command2.Value
DoCmd.OpenForm strName

End Sub

I really appreciate it.
 
Upvote 0
I also tried this and it didn't work?

Private Sub Command2_Click()
Dim strName As String

strName = Me.Combo2.Value
DoCmd.OpenForm strName

End Sub
 
Upvote 0
Sorry about the multiple responses. I'm not sure I know what you mean by the number of the combo box. Would that be text0 or combo0?
 
Upvote 0
SELECT [name] FROM MSysobjects WHERE ([MSysobjects].[Type]=-32768) ORDER BY [name];

This is the code to pull up a all the forms in a combo box...How can I edit this to pull up all reports in a combo box? Thank you.
 
Upvote 0

Forum statistics

Threads
1,221,596
Messages
6,160,719
Members
451,666
Latest member
GCS1998

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top