Link to home
Start Free TrialLog in
Avatar of happyboy25
happyboy25

asked on

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
Avatar of ComputerWiz
ComputerWiz


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.

Avatar of happyboy25

ASKER

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
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
ASKER CERTIFIED SOLUTION
Avatar of dwfallin
dwfallin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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
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

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?


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.

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
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