Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Message Box Working-But am getting a funky result.

Status
Not open for further replies.

Kallen

MIS
Aug 14, 2001
80
US
Hi Everyone,

I have a form that is used to add new information that is required. There are 4 fields that are required, and I have them tagged as required. I have the following code on before update of the form itself.

Dim ctl as control

for each ctl in controls
if ctl.tag = "Required" then
if IsNull(ctl.value) then
msgBox ctl.name & " is a required field"
DoCmd=Cancel Event
exit for
end if
end if
next
end sub

This seems to be working fine w/ one exception. What I get after the message box that I want to appear, is another message box that I did not create that says "the previous operation was cancelled". Does anyone know what is wrong w/ my code to make this happen?

FYI: This is based on a query, so I don't think making it required at the table level will help me (I tried & it did not work)

Thanks, and I hope all of you have a good weekend.


 
I believe that this is happening because you cancelled the update event of the form (docmd=cancelevent). To get around this, you can put 'docmd.setwarnings false' before that line of code. Just remember to set it back to true afterward.
 
I will try that out. I thought it was something like that.

Thanks
 
Hi AccessSQLUser,

Thanks for your reply

I tried your suggestion, and feel that I am doing it incorrectly. What I did was put in DoCmd.setwarnings=false
before DoCmd.cancelevent. I put in DoCmd.setwarnings=true
after DoCmd.cancelevent. What happened when I tried to run this was an error that said "Compile Error: Argument not Optional. I think the problem in in my syntax, but not sure.

I am really new to programming, and still have problems with syntax and debugging.

Thanks for your help
 
Try:

DoCmd.SetWarnings False
Do Something here...
DoCmd.SetWarnings True


Terry M. Hoey
 
i think the problem is in yor sintax!!
instead of "docmd=cancel event", try "docmd.CancelEvent"
this should do the trick!

Hope this helps!! Good luck in your db!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top