Combo box opening forms.

  • Thread starter Thread starter rsm169
  • Start date Start date
R

rsm169

I have a form with a combo box with some data in it. When a user clicks the
data in the box I want to open the related form. What would that code look
like?
 
rsm169 said:
I have a form with a combo box with some data in it. When a user clicks the
data in the box I want to open the related form. What would that code look
like?

You mean the user selects somthing in the combo box?

You would use the after update event of the combo box.


You'll have to explain a bit more in detail as to what you mean by related
form......

the after update event of the combo box will look something like


docmd.OpenForm "nameOfForm"
 
I have a form with a combo box with some data in it. When a user clicks the
data in the box I want to open the related form. What would that code look
like?

Private Sub cmdOpenForm_Click()
DoCmd.OpenForm "YourFormNameHere",,,"[ID] = " & Me!cboID
End Sub

I'm assuming that the combo box is named cboID and that it contains a numeric
ID field, and that you want to open YourFormNameHere displaying the selected
record's data.
 
To both Albert and John,

Yes my combo box already has data in it, right now there are three choices.

Endmills
Drills
Reamers

When the user clicks Endmills, I want a form named EndmillsFRM to pop open.
The same is true for the other two choices. I would like the form to remain
open while the data is entered and then closed at the start of the next
record.

Thank you both for taking time to help.

Mike

John W. Vinson said:
I have a form with a combo box with some data in it. When a user clicks the
data in the box I want to open the related form. What would that code look
like?

Private Sub cmdOpenForm_Click()
DoCmd.OpenForm "YourFormNameHere",,,"[ID] = " & Me!cboID
End Sub

I'm assuming that the combo box is named cboID and that it contains a numeric
ID field, and that you want to open YourFormNameHere displaying the selected
record's data.
 
To both Albert and John,

Yes my combo box already has data in it, right now there are three choices.

Endmills
Drills
Reamers

When the user clicks Endmills, I want a form named EndmillsFRM to pop open.
The same is true for the other two choices. I would like the form to remain
open while the data is entered and then closed at the start of the next
record.

Thank you. That was not at all evident from your original post, and is quite a
different problem! Remember, you can see your computer - we cannot!

How are these three forms different? Do you have separate forms, separate
tables, separate queries for the three kinds of tools? If so, I suspect your
table structure needs attention. But if it's legitimate, you'll need code
like:

Private Sub comboboxname_AfterUpdate()
Dim strForm As String
Select Case Me!comboboxname
Case "Endmills"
strForm = "FRMEndmills"
Case "Drills"
strForm = "FRMDrills"
Case "Reamers"
strForm = "FRMReamers"
Case Else
Msgbox "Please choose a tool type"
strForm = ""
End Select
If strForm <> "" Then
DoCmd.OpenForm strForm, DataMode := acFormAdd, WindowMode := acDialog
End If
End Sub

You'll also need to add code in each form's AfterUpdate event to close the
form.

You *could* use code instead of the Select Case... End Select like

strForm = "FRM" & Me!comboboxname

but that would constrain your choice of form names and could cause problems
(say if you need an altered form with a different name for testing). Or you
could use a two column combo box with the actual form name in the bound (but
concealed) column.


Just an oddity note: in the summer of 1965 my first wage-paying job was
working at a company using diamond grinding wheels to finish tungsten carbide
endmills, drills and reamers to 0.0002" or better tolerance...
 
My three forms are all subclassed from the main products form, every endmill
is a product, but not every product is an endmill. I am pretty sure the
tables are in good order because you helped me with them a while back.

I went and took your sample code and made some edits to match what is in my
db so here is what it looks like now. I made no changes to any of my other
forms.

Private Sub CategoryID_AfterUpdate()
Dim strForm As String
Select Case Me!CategoryID
Case "ENDMILL"
strForm = "EndmillsFRM"
Case "DRILL"
strForm = "DrillsFRM"
Case "REAMER"
strForm = "ReamersFRM"
Case Else
MsgBox "Please choose a tool type"
strForm = ""
End Select
If strForm <> "" Then
DoCmd.OpenForm strForm, DataMode:=acFormAdd, WindowMode:=acDialog
End If
End Sub

When I click a choice in the combo box it goes right to the msgbox “please
choose a tool type†Any ideas?

I have been a machinist all of my career and use the very kind of tools on a
daily basis you were grinding back in 65. It is always a pleasure to meet
someone with which you have a common knowledge.
 
Private Sub CategoryID_AfterUpdate()
Dim strForm As String
Select Case Me!CategoryID
Case "ENDMILL"
strForm = "EndmillsFRM"
Case "DRILL"
strForm = "DrillsFRM"
Case "REAMER"
strForm = "ReamersFRM"
Case Else
MsgBox "Please choose a tool type"
strForm = ""
End Select
If strForm <> "" Then
DoCmd.OpenForm strForm, DataMode:=acFormAdd, WindowMode:=acDialog
End If
End Sub

My guess is that the CategoryID combo box actually has a Number field (perhaps
invisible) as its bound column, so the Value of the combo will be 3 or 21 or 7
- and will never be the text string "ENDMILL".

Try

Select Case Me!CategoryID.Column(1)

to extract the (text) second column from the zero-based Column property -
adjust as needed to extract whichever column in the combo box contains the
text.
 
You sir are amazing, It works perfect!

Is it possible to have the pop up forms appear at a designated place in the
form or in a permanent window instead of the middle of the screen?
 
Is it possible to have the pop up forms appear at a designated place in the
form or in a permanent window instead of the middle of the screen?

Well, I don't use popups much... but I think if you open the form in design
view, position it where you want it, set the AutoCenter and AutoResize
properties to No and save it, it will stay put.
 
Back
Top