Error Message if no selection is made in List Box

R

Ruth

I'm having trouble making this work. I have a form that displays an
unbound listbox of existing assessments in my DB (Access 2003). When
an assessment is selected, the user clicks the Open button on the
form, and the following code executes.

Private Sub btnOpenExstAssess_Click()
On Error GoTo Err_btnOpenExstAssess_Click

Dim stDocName As String
Dim StLinkCriteria As String

If Me![lstAssess] = Null Then
MsgBox "Please select an Assessment from the list.",
vbCritical, "No Selection Made"
Else
stDocName = "Question Main"
StLinkCriteria = "[ReviewID]=" & "'" & Me![lstAssess] & "'"
DoCmd.OpenForm stDocName, , , StLinkCriteria
DoCmd.Close acForm, "frmOpenExist"
End If

Exit_btnOpenExstAssess_Click:
Exit Sub

Err_btnOpenExstAssess_Click:
MsgBox Err.Description
Resume Exit_btnOpenExstAssess_Click

End Sub

The If part doesn't work. It still opens a blank form which is missing
all my custom navigation buttons, including the button that closes the
form and returns to the Main Menu. Basically, if a user doesn't select
an assessment from the list, they are stuck on a dead end form.

The underlying VB for the listbox's contents is:
SELECT tblReviews.ReviewID, tblReviews.OrgName, tblReviews.RevDate
FROM tblReviews
ORDER BY tblReviews.RevDate DESC , tblReviews.OrgName;

Thanks for any help!

Ruth
 
B

Bob Larson

You don't check if something is equal to null. Null is not a value, but a
state.

use

If IsNull(Me![lstAssess]) Then

instead


--

Thanks,

Bob Larson
Access MVP
Administrator, Access World Forums
Utter Access VIP

Free Access Tutorials and Resources: http://www.btabdevelopment.com
 
R

Ruth

Thanks, Bob! I had tried that earlier but obviously had the sytax
wrong (since I couldn't get it to work)! Thanks very much for your
help.

Ruth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top