Skip Event Procedure if form is null

S

shellsusenetgroups

Hello,

I have a form that I have created that has an OnClose event. The
event opens a new form (fShowIncidentID) which gives the user their
incident number for what they have just entered. However, is a user
just opens the form and closes without doing any entry, then they get
my fShwoIncidentID with no incident number because no record was
saved. I would like to suppress my fShowIncidentID form if the user
did not enter any data. Is that possible? Thanks in advance!!

Here is my current code for the close event:
Private Sub Form_Close()

On Error GoTo Err_Command112_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "fShowIncidentID"

stLinkCriteria = "[Incident Number]=" & "'" & Me![Text42] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command112_Click:
Exit Sub

Err_Command112_Click:
MsgBox Err.Description
Resume Exit_Command112_Click

End Sub
 
D

Douglas J. Steele

If IsNull(Me![Text42]) = False Then
stLinkCriteria = "[Incident Number]=" & "'" & Me![Text42] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

or, my preference,

If Len(Me![Text42] & vbNullString) > 0 Then
stLinkCriteria = "[Incident Number]=" & "'" & Me![Text42] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

(I prefer the second because it checks for both Null or a zero-length string
("").
 
S

shellsusenetgroups

Thank you SO much for the reply, I really appreciate it. I am pretty
good in Access but totally new to VBA. I tried putting that code
about everywhere I could think of and couldn't get it to work. Where
do I insert it?
Sorry to be an idiot,
Michelle
 
D

Douglas J. Steele

Private Sub Form_Close()

On Error GoTo Err_Command112_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "fShowIncidentID"

If Len(Me![Text42] & vbNullString) > 0 Then
stLinkCriteria = "[Incident Number]=" & "'" & Me![Text42] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

Exit_Command112_Click:
Exit Sub

Err_Command112_Click:
MsgBox Err.Description
Resume Exit_Command112_Click

End Sub
 

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

Similar Threads


Top