?
Solved

Error Handling in Access 97

Posted on 2003-02-23
11
Medium Priority
?
289 Views
Last Modified: 2012-05-04
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
0
Comment
Question by:happyboy25
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
11 Comments
 
LVL 1

Expert Comment

by:ComputerWiz
ID: 8006581

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
 

Author Comment

by:happyboy25
ID: 8006616
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
 

Author Comment

by:happyboy25
ID: 8006720
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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Accepted Solution

by:
dwfallin earned 40 total points
ID: 8006924
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
 

Author Comment

by:happyboy25
ID: 8007022
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
 

Expert Comment

by:dwfallin
ID: 8007119
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
 

Author Comment

by:happyboy25
ID: 8007237
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
 

Expert Comment

by:dwfallin
ID: 8007478
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
 
LVL 1

Expert Comment

by:ComputerWiz
ID: 8009785


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
 

Author Comment

by:happyboy25
ID: 8012960
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
 

Author Comment

by:happyboy25
ID: 8013108
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question