How do I check if combobox in form is empty (or null)

MAQjr

New member
Local time
Today, 07:40
Joined
Nov 13, 2015
Messages
5
Hi,



I have a simple combo box where a user makes a choice, clicks a command button, and the corresponding form opens so the user can perform edits. That piece works fine. I cannot validate whether the combo box is actually empty when the command button is clicked (thereby redirecting user to make a choice).


Here is my code:

Code Tags added by UG
Code:
Private Sub btnOpenForm4Editing_Click()

Dim stDocName As String

On Error GoTo HandleError

stDocName = Me.cboTableNames

If IsNull(Me.cboTableNames) Then
         MsgBox "Please Choose a Form Name!", vbOKOnly
         Me.cboTableNames.SetFocus
Else

    'Open the form identified in the drop down choice
         DoCmd.OpenForm stDocName

End If

HandleExit:
    Exit Sub
    
HandleError:
    MsgBox Err.Description
    Resume HandleExit
    
End Sub

Why doesn't my validation work?
 
Last edited by a moderator:
So, what is actually happening when the combo is empty and the user clicks the button?
 
Invalid use of Null
 
If I understand your question correctly, the error is on this line:


If IsNull(Me.cboTableNames) Then
 
Hi. I think I see the problem. Try it this way:
Code:
Private Sub btnOpenForm4Editing_Click()

On Error GoTo HandleError

If IsNull(Me.cboTableNames) Then
         MsgBox "Please Choose a Form Name!", vbOKOnly
         Me.cboTableNames.SetFocus
Else

    'Open the form identified in the drop down choice
         DoCmd.OpenForm Me.cboTableNames

End If

HandleExit:
    Exit Sub
    
HandleError:
    MsgBox Err.Description
    Resume HandleExit
    
End Sub
 
That worked! So the use of a variable name was the problem?


Thanks for the help, this has vexed me for a week. I truly appreciate the assist.
 
That worked! So the use of a variable name was the problem?


Thanks for the help, this has vexed me for a week. I truly appreciate the assist.
Hi. You're welcome. Yes, assigning a null value to a String variable was the problem. Good luck with your project.
 

Users who are viewing this thread

Back
Top Bottom