Access VBADiscuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
I am trying to have my database open a form if one option from my combo box is selected.
I.E.
In the form "IncidentKind" I have a combo box called "IncidentKind", with multiple options. If the user selects FallofHeight, I want the Form "FallOfHeight" to open. I do not where I am going wrong, please help.
This is easy. The combo box is capturing a primary key for the value FallOfHeight, I assume. I also assume the user selects a field from the combo box, and then clicks a button to open the other form. Is there already a form that is opened somehow?
Anyway, you have to capture the value from the combo box, then check it in an If Then End If, like this:
(This example assumes that 1 is the PK for FallOfHeight.)
'==========
Private Sub btnYourButton_Click()
On Error GoTo Err_btnYourButton_Click
Dim stDocName As String
Dim intMyComboBox As Integer
intMyComboBox = Me.MyComboBoxName
If intMyComboBox = 1 Then
stDocName = "frmFallOfHeight"
DoCmd.OpenForm stDocName
Else
stDocName = "frmDefaultForm"
DoCmd.OpenForm stDocName
End If
Sorry, I used MyComboBox as the name of the box you have called "IncidentKind."
Also, you can put this on the combo box's After Update event, but I usually put this on a button's on click event, to give the user the option to open the next for or not.
Thanks for your prompt reply. I think I see where I was going wrong, and I am going to try and impliment this in my database. I will let you know how it goes.