Problem with validation on a form

law

Registered User.
Local time
Today, 06:06
Joined
Feb 14, 2004
Messages
26
Hello,

Can anyone help with this problem I am having with a form. On this form I currently have several text boxes on the form & also I have a save button. when I click save if the text boxes contain NULL then I want to display a message box saying that they need to eneter data in them. the [event procedure] is under the save button click_event. The code is shown below

Private Sub saveRecord_Click()
On Error GoTo Err_saveRecord_Click

If IsNull(txtJobDetailsStaffNo) Then
GoTo Err_saveRecord_Click

Else
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Exit Sub

Err_saveRecord_Click:
MsgBox "You must enter data in this field", vbCritical, "Data requested"

End If
End Sub

The problem is when you ENTER a value it still displays the msgbox & I dont want that, when data is in the text box I would like it to save.

Any ideas?

Thanks
 
The IF and Then statment was incomplete.

try this

Private Sub saveRecord_Click()


If IsNull(txtJobDetailsStaffNo) Then

MsgBox "You must enter data in this field", vbCritical, "Data requested"

Else
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Exit Sub

End If
End Sub
 
My issue is similar, so I hope you don't mind me posting here. I am having an issue with getting a frame that is null to cancel an event and give a message...

Code:
Private Sub cmdOpenAJobReport_Click()
On Error GoTo Err_cmdOpenAJobReport_Click

    Dim stLinkCriteria As String
    stLinkCriteria = Me.cmbJobListing
    
    DoCmd.SetWarnings False
    If Me.FrmJobReportCH.Value = 0 Then
    MsgBox "You must choose whether you want a candidate or hire report", vbCritical, "Please choose report type"
    Else
    DoCmd.OpenReport gstrJobReportName, acPreview, , "[JobID] =" & stLinkCriteria, acWindowNormal
    End If
    DoCmd.SetWarnings True
    
Exit_cmdOpenAJobReport_Click:
    Exit Sub

Err_cmdOpenAJobReport_Click:
If Err <> 2501 Then
    msgbox Err.Description
  End If
    Resume Exit_cmdOpenAJobReport_Click
    
End Sub

If I put the if as if the frame is null, I get a message Oject required, no matter what I do. If I have value = 0 it does work.

What I have on the form is a frame with 2 buttons - candidates and hires.

In the after event of the frame, I have a global string (gstrJobReportName) = the corresponding job report (candidate or hire).

Then I have a combo for criteria.

If the user does not pick a button, I want that message in the code to come up, not an Access message. I can't seem to turn off the message when I don't pick a button, and mine never comes up. With choosing a button and combo criteria, I get the right reports. I am like 75% there.

Anyone got an idea for the last 25%?

Thanks!
 

Users who are viewing this thread

Back
Top Bottom