Ruchir Sheth
Ruchir Sheth

Reputation: 15

Open Form to a specific record as per value of Combobox. And Popup Error Message if no value is selected in Combobox

I am able to open the Form with the code below

**Private Sub EDit_Click()

DoCmd.OpenForm "State", acNormal, "", "[S_ID]=" & [RM_State], , acNormal

End Sub**

What I want is to add a Popup Error Message saying "Select the State from the List." when the combobox value is null (nothing is selected)

I have tried below code but it seems code is not right

**Private Sub EDit_Click()

DoCmd.OpenForm "State", acNormal, "", "[S_ID]=" & [RM_State], , acNormal

If (RM_State = 0) Then

MsgBox ("Select the State from the List.") Return

End If End Sub**

I am getting Error Run-Time Error'3075' - ERROR IMAGE

Upvotes: 0

Views: 31

Answers (1)

vbakim
vbakim

Reputation: 621

I would use IsNull() function for checking RM_State..

Private Sub EDit_Click()
    If IsNull(RM_State) Then
        MsgBox "Select the State from the List."
        Exit Sub
    End If
    DoCmd.OpenForm "State", acNormal, "", "[S_ID]=" & RM_State, , acNormal
End Sub

Upvotes: 0

Related Questions