Macro

superrob5

Registered User.
Local time
Today, 17:13
Joined
May 8, 2003
Messages
99
Ok I am starting to get the hang of access.

The problem I am having is with the macors
I am checking for a validation. If its is not valid to the rule I have the macro displaying a message. Then going to that control then canceling the event. This all takes place in the before update. The only problem is after the message comes up it says operation canceled. I know this has to do with the canceled event. Is there a way to cancel the event with out this message. I dont want to have more then the one error come up. I have attached the db its in access 2000.


Rob
 

Attachments

DoCmd.SetWarnings False

and


DoCmd.SetWarnings True


The former turns warning messages off and the latter restores them.
 
I went to the validation macro that I created
and before the first test of validations I added

Setwarnings No

and I stilll get that extra message when I click on the close button, or save button.


Thanks

Rob
 
Last edited:
If you can use code, and I see that you can, I'm wondering why on Earth you are using macros at all - they are slow and don't have any error handling capabilities.

To your problem, though.

Remove the form's BeforeUpdate() event and put this on the New record button:

Code:
Private Sub cmdNew_Click()
On Error GoTo Err_cmdNew_Click

    With Me
        If (IsNull(.HIVPOTC) And Not IsNull(.Result)) Then
            MsgBox "HIVPOTC has no value or take out Result", vbQuestion, "PCAP ERROR MESSAGE"
            .Result.SetFocus
            Exit Sub
        End If
        
        If (IsNull(.Result) And Not IsNull(.HIVPOTC)) Then
            MsgBox "Result has no value or take out HIVPOTC", vbOKOnly, ""
            .HIVPOTC.SetFocus
            Exit Sub
        End If
    End With
    
    DoCmd.GoToRecord , , A_NEWREC
    
Exit_cmdNew_Click:
    Exit Sub

Err_cmdNew_Click:
    MsgBox Error$
    Resume Exit_cmdNew_Click
    
End Sub
 
the problem with that is on the form there is a close button. on the form. I will add this code to the save button and the add new button. But what do I do if the user tries to close with the close button. also what does the with me do?? doesnt look like access 2.0 doesnt seem to recognize with me



Rob
 
Last edited:
superrob5 said:
what does the with me do?? doesnt look like access 2.0 doesnt seem to recognize with me

Forms and reports, if they have code behind them, have this code in a class module. Independant class modules also let you use the Me statement.

Me represents the 'class', in this case your form.

So, the code is saying, With This Form

I've never used Access 2.0 so I don't know if class modules were used back then so can't help in that respect.
 

Users who are viewing this thread

Back
Top Bottom