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.
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"
stDocName = "frmDefaultForm"