Error Handling in Access 97

Hi Experts,

I am back again. Thanks for all the tips and solutions I get from the experts.

Well, I have encounter some problems yet again.(Beginner that's why)

How do I ignore all the inputs in a form and Close the form without the Error massage pop up before the form closes ?

I have a field which is input masked as date.
When I keyed in 56/56/56(Invalid) and I pressed the close button(X) at the top right hand corner of the form, I get an error message telling me it's an invalid entry, then it prompt me again to select whether to exit and not save the records or to cancel to go back again.The massage is "You can't save this record at this time"
By the way, I didn't even try to save the records as all the actions are done only when the  save button is clicked, meaning all the saving code is at the On Click Event.

I used the OnClose and OnError property of the Form to handle the Error.

"On Error Resume Next"

This doesn't work for me and the two massage kept popping up.

Please Advice.
BEGINNER
happyboy25Asked:
Who is Participating?
 
dwfallinConnect With a Mentor Commented:
i don't think you're getting a code error - its an auto-validation error. ie, in the field_lostfocus or field_change event is where this is happening. my guess is you won't be able to do anything in the close event (or click event of a button) because the lostfocus will occur first! you may want to make the field a generic text field, then use code to validate the date value in your save code (that way, you won't get the erroron the lostfocus)
0
 
ComputerWizCommented:

why don't you put a checkdata function OnClose to see if all the required fields have data.  If no data, do a docmd.cancel

Also, add an "isdate(value)" function to your date field on the update event property, if it returns false then display a message "invalid date" and return the focus to the control.

0
 
happyboy25Author Commented:
Hi ComputerWiz

For all the fields I handle Null values thru :-

If IsNull(Me![FOCentry]) Then
                MsgBox "Enter FOC !!!"
                DoCmd.GoToControl "FOCentry"
End If

But the thing is that I want the Form to ignore all inputs and close the form !

I am using Input Mask Property to validate the data in the textbox.

But the point is , I just want the form to close.

Do advice
BEGINNER
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
happyboy25Author Commented:
Hi experts,

Just another note :-

I have tried using the On Error Event to intercept the msg.
But "the On Error Goto.." line fail to work ! I don't really understand it but, when I use the Breakpoint the thing just skip that line and display the error mssage.

DO Advice
THanks,
BEGINNER
0
 
happyboy25Author Commented:
Hi dwfallin
Thanks for the prompt reply !

Can you please say a bit more about your methods ?
Or maybe if possible provide a simple example for me to see the point ?

Thanks,
BEGINNER
0
 
dwfallinCommented:
instead of using inputMask property of the text field, leave the validation of fields to pieces of code. take the suggestion of computerwhiz to create a function called checkdata, but call it on form.beforeupdate. the function will just doublecheck fields that you need to be a certain format (like dates):

function bCheckData() as boolean
on error goto bCheckData_Exit
  bCheckData = False

  'assume text1 should be a date field
  'if text1.text is NOT a date, the error will
  'will be trapped and this function will return
  'false. as an alternative, you could highlight
  'text1 and give the user a messagebox telling them
  'to correct it
  text1.text = format$(text1.text, "mm/dd/yyyy")

  bCheckData = True

bCheckData_Exit:
  if err.number <> 0 then msgbox "Error in bCheckData: " & err.description

the point being, since the text of the field is not being validated by the control (textbox) itself, you can ignore all data in the form_close event and do what you originally wanted to do.

end function
0
 
happyboy25Author Commented:
Hi dwfallin

Can I use this instead ?

Me!Registered.Format = "Yes/No"

Because I don't really understand your code.

For example ,
 text1.text = format$(text1.text, "mm/dd/yyyy")

meaning it will format the data in the textbox to be a ate format is it ?

Do Advice
BEGINNER

0
 
dwfallinCommented:
i'm not sure what you're asking to use. if you take the edit mask off of the date field, does your form_close code work?
0
 
ComputerWizCommented:


OIC... modify your Null function to display the message "Okay or Cancel" as you mentioned early.  I don't want to give you exact code, I want to make you think about your logic and the logical placement of your data validation and close event.

It appears that your question is not about code, rather logic.

Instead of having seperate events, put the null check and the close form all in one, that way if the user truly meant to leave out the data so to close the form, then that is handled at the same time that the data is being checked for nulls.

0
 
happyboy25Author Commented:
Hi experts,

Sorry for the late reply.
When I take out the mask, the Error still exist. So I believe the source of the problem is the Control Source of the Textbox.

By the way, ComputerWiz , you mean that I check for NULL at the end of the program maybe at the OnClick event is it ?

hmmmm .... That's what I have done in the first place but I feel that if the user is able to enter a form full of rubbish before the program rejects them and ask for re-entry again, it will not be very nice right ?


One question,

If I use .AddNew and .Update can I leave the Control Source of all the textboxs blank ?

Do Advice
BEGINNER
0
 
happyboy25Author Commented:
Hi all,

Just another note to add, presently I am doing the checks via OnEnter Event,meaning Upon Entry of the next textbox, I will check whether the previous Box is a NULL, if it is, then I will Set Focus to the previous textbox.


Thanks
BEGINNER
0
All Courses

From novice to tech pro — start learning today.