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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

More meaningful messages

Status
Not open for further replies.

mattl72

IS-IT--Management
Oct 2, 2002
24
0
0
US
Hi all

I am developing a database that tracks orders. One of the fields on the forms is salesperon_no (SP_No). It is a required field. When a user tries to save the record, either by tabbing through to a new order or by clicking a save button, access brings up a message saying that "The field Orders.SP_No can't contain a Null value because the required property for this field is set to True. This is kind of cryptic to some of the end users. Is there anyway to display a more meaningful message? I know I need to bring up a msgbox but I cant get it to fire right. I thought I might be able to use error trap but I don't think access treats it as an error.

I do have some validation that prompts them for a SP_No if the field is null and loses focus, but it doesn't stop someone from navigating around it with a mouse.

Any help would be appreciated

Thanks,
Matt
 
The way that I have handled this is to keep the user from tabbing through to a new record as you indicated. I always require the user to use a Save button which has code in it that analyzes all required fields before the save takes place. This way I can control the messages and prompts for correctly entered data. I usually do this through a call to a subroutine like Call AnalyzeScreen. AnalyzeScreen is a subroutine that performs all of the analysis of the screen controls and displays messages. When i find a control that needs editing or entry I display the message and set the focus back to that control and exit the sub without executing the Save record code.

Now the trick is to keep the user from tabbing through to the next record. This requires you to set the Form property Cycle to Current Record. This will cycle the focus from the last bound control on the form to the first bound control on the form without performing the save operation. It stays in the same record.

If you have any questions please get back with me. Bob Scriver
 
Or you can use the Form's Error event:

Private Sub Form_Error(DataErr As Integer, Response As Integer)

'this is to find the error code and general description
MsgBox DataErr & AccessError(DataErr)

Select Case DataErr 'this is the error number

Case 3022 'I know this is duplicate key
Response = acDataErrContinue 'don't display default message
MsgBox "Hey! Don't enter duplicetes!"

Case Else
'here you have to trap other errors
End Select

End Sub

Good luck
[pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
Thanks for your responses.

In the past, I have set the cycle records property to current record and forced them to click a save button. It seems to work pretty well. This client wants to be able to tab through to a new record though (don't ask me why). I'll try that error event and see what happens.

Thanks again :)
 
If they want to tab through to a new record you can put the Call to the procedure in the On Lost Focus event of the last tab control. Then either find errors and correct them or allow the cursor to continue and go to the next record.

I have also used a Transparent Button Control as the last tab control and executed this code in the OnGot Focus of that button. This will trigger going back up in the form to fix the bad data or executing a SendKeys "{tab}" to move to the next record.

Different ways to skin the cat. Bob Scriver
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top