Openform to open different form

kigor

Registered User.
Local time
Today, 23:49
Joined
Apr 24, 2010
Messages
19
Hi,
I look for this solution but without solution.
Problem is that dependent of number in one field (from 1 to 5) cliking bottom will open new form with openform.
Problem is that if field criteria=1 will open Form1, if field criteria=2 will open form2 etc. So complete different form. And all of this new Form1, form2... are made with different query.
Some idea? My VBA coding is very poor
 
Last edited:
Kigor,

You could use a Select Case statement to filter out the field number and then open the correct form. You could use something like the following which is based off a Listbox with options and if a user clicked an option then something would happen. I changed it a little for your example.


Private Sub OpenFormOption_Click()
Select Case Me.OpenFormOption
'Filter choices
Case 1
Me.OptionField = "1"
DoCmd.OpenForm Form1, acNormal, , , acDialog
Case 2
Me.OptionField = "1"
DoCmd.OpenForm Form2, acNormal, , , acDialog
Case 3
Me.OptionField = "1"
DoCmd.OpenForm Form3, acNormal, , , acDialog
End Select
End Sub
Hope that helps,

Joe
 
Hi,
thanks for your fast replay.
I paste your solution, change name to real one but still receive mistake or better: "Run-time error: 438, Object doesn't support this property or method".

I simple on main form add bottom with Openform method and call it "Izracunajbrojprimjeraka". Then delete code, correct your one with real name and receive this:

Private Sub Izracunajbrojprimjeraka_Click()
Select Case Me.Izracunajbrojprimjeraka
'Filter choices
Case 1
Me.E15_ID = "1"
DoCmd.OpenForm [E21_PRETPLATE Voce], acNormal, , , acDialog
Case 2
Me.E15_ID = "2"
DoCmd.OpenForm [E21_PRETPLATE Panorama], acNormal, , , acDialog
Case 3
Me.E15_ID = "3"
DoCmd.OpenForm [E21_PRETPLATE Arcobaleno], acNormal, , , acDialog
Case 4
Me.E15_ID = "4"
DoCmd.OpenForm [E21_PRETPLATE Battana], acNormal, , , acDialog
Case 5
Me.E15_ID = "5"
DoCmd.OpenForm [E21_PRETPLATE Voce], acNormal, , , acDialog

End Select
End Sub

What I made wrong?
 
Ok, I think I understand now what you are needing. I have attached a file for you to look at that should answer your question on how to do it.
The file has a text box, list box and command button. The text box you can either input a number manually or you can choose from the list box and it will populate the text box automatically. Either way, whenever you get the correct number in the text box field, you can hit the command button (Open Form) and it will open to the form that was chosen.

If you have any questions, please feel free to ask....:)
 

Attachments

In case anyone else wanted to see what code I put behind the example, I have placed it here so that nobody had to download it to see it.

'Placed behind the OnClick event of the Command Button

Private Sub Command6_Click()
Dim sNumberValue As Integer 'Dim Text box for number
Dim sTextBoxNumber As String 'Dim List box choice

'Prepares Textbox for choices
sTextBoxNumber = Me.E15_ID
If sTextBoxNumber = "1" Then
DoCmd.OpenForm "frmVoce", acNormal
ElseIf sTextBoxNumber = "2" Then
DoCmd.OpenForm "frmPanorama", acNormal
ElseIf sTextBoxNumber = "3" Then
DoCmd.OpenForm "frmArcobaleno", acNormal
ElseIf sTextBoxNumber = "4" Then
DoCmd.OpenForm "frmBattana", acNormal
ElseIf sTextBoxNumber = "5" Then
DoCmd.OpenForm "frmVoce2", acNormal
End If
End Sub

'The following allows the user to either just view the choices in the Listbox or click on them and populate the Textbox with a number needed for the OnClick event of the command button.

Private Sub List4_Click()
Select Case Me.List4
Case 1
Me.E15_ID = "1"
Case 2
Me.E15_ID = "2"
Case 3
Me.E15_ID = "3"
Case 4
Me.E15_ID = "4"
Case 5
Me.E15_ID = "5"
End Select
End Sub



Joe
 
Thank you very much. Sorry I just see never replay here :(
It resolve all my problem. Great solution
 

Users who are viewing this thread

Back
Top Bottom