Display msgbox if required field is blank

cbsull

New member
Local time
Today, 16:15
Joined
Feb 21, 2006
Messages
8
On my form, I have a combo box for a required field. Once the user populates the data they click a button which, if the required field is populated, will open another form. If the required field is not populated, I do not want to open the other form but instead want a msgbox to appear. Below is my code:

Code:
Private Sub SaveCustomerInfo_Button_Click()

If Me!cmbo_CorporateGovernance.selectedIndex = -1 Then
      MsgBox "You must enter a value for the Corporate Governance"
      Exit Sub
End If
    
        DoCmd.Close acForm, "Frm_NewCustomerInfo"
        DoCmd.OpenForm "NewFrm_qry_CusIns_GenBusSit_General", acNormal, "", "", , acNormal
End Sub

I believe the error lies in my If statement but I don't know where my mistake(s) are. Can someone please help me! :confused:
 
It looks like it's throwing the error on the if statement. If they can only choose one option from the combo box, you might try just making the action on "After Update". Or instead of -1, do > 0.

You can find out for sure. Place a runtime break on the if statement and look at the value of the combo box. Just make a variable equal to Me!cmbo_CorporateGovernance and check the value in the watch list.
 
Thanks for your input. I was able to determine the solution. Attached is my code.

:D

Code:
Private Sub SaveCustomerInfo_Button_Click()

Dim combovalue As Double

If Me.cmbo_CorporateGovernance.ListIndex < 0 Then
    
    MsgBox "You must select a value for the Corporate Governance."
    Me.cmbo_CorporateGovernance.SetFocus

Else
        
    DoCmd.Close acForm, "Frm_NewCustomerInfo"
    DoCmd.OpenForm "NewFrm_qry_CusIns_GenBusSit_General", acNormal, "", "", , acNormal

End If

End Sub
 
What is the Dim combovalue As Double for? You are not using it.
 
The "Dim combovalue..." is actually being used in my Else statement. I have additional code that I hid in order to make my question simplier to understand.

Thanks for questioning that! :D
 

Users who are viewing this thread

Back
Top Bottom