error message (1 Viewer)

Beany

Registered User.
Local time
Today, 23:17
Joined
Nov 12, 2006
Messages
155
Hi folks,

i have a form that allows me to save mobile phone details.

The problem with this form is that if its incomplete and i click 'x' it shows me the validation message followed by an error message (which is attached with this thread).....

why is that? is there anyway i can exit the form (incomplete) without the valdation message or error message occuring???
 

Attachments

  • error.bmp
    39.8 KB · Views: 109

boblarson

Smeghead
Local time
Today, 16:17
Joined
Jan 12, 2001
Messages
32,059
Beany:

You could put this in the on Close event of the form:
Code:
    If Me.Dirty Then
        Me.Undo
    End If
 

Beany

Registered User.
Local time
Today, 23:17
Joined
Nov 12, 2006
Messages
155
Alright Bob?

ive tried(with ur code) the following on the On Close event in form properties:

Private Sub Form_Close()

If Me.Dirty Then
Me.Undo
End If

End Sub



but im still getting the same error? am i doing sumat obviously wrong?
 

boblarson

Smeghead
Local time
Today, 16:17
Joined
Jan 12, 2001
Messages
32,059
Not sure, as it worked for me in a test db. Maybe there's something else involved. Hopefully someone else might have an idea.
 

Beany

Registered User.
Local time
Today, 23:17
Joined
Nov 12, 2006
Messages
155
thanx Bob,

any1 else with an idea?
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 23:17
Joined
Sep 12, 2006
Messages
15,614
you get this message because access tries to save the current record when you close the from, and there is something invalid in this record - eg required fields not completed.

when you close the form, the record tries to save, and the untrapped error you are seeing occurs BEFORE the close form, I think

you can trap this either in the form beforeupdate event, or better still in the form error event, but you need to do a bit of work to find out the error number etc, before you decide to disregard this - as it may be a genuine edit that you don't want to automatically disregard

alternatively, if its the username being pre-filled that causes the dirty record, you could set this when you add the record.

finally, if you are only using this form to add new data, you could change it to an unbound form, and add the record via a recordset when you click the add button. (it may actually be an unbound form already)

hope these thoughts help
 

Beany

Registered User.
Local time
Today, 23:17
Joined
Nov 12, 2006
Messages
155
cheers gemma, you gave me a better idea,

as you know, Ive got an ADD button with the following code:

Private Sub addrec_Click()
On Error GoTo Err_addrec_Click

DoCmd.GoToRecord , , acNewRec

Exit_addrec_Click:
Exit Sub

Err_addrec_Click:
MsgBox Err.Description
Resume Exit_addrec_Click

End Sub


and i have some validations through the following code:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim blnValidation As Boolean
Dim strValidate As String

strValidate = "These item(s) were not filled out and are required:" & vbCrLf & vbCrLf

If IsNull(Me.username) Or Me.username = "" Then
blnValidate = True
strValidate = strValidate & "Username" & vbCrLf
End If

If IsNull(Me.number) Or Me.number = "" Then
blnValidate = True
strValidate = strValidate & "Number" & vbCrLf
End If

If blnValidate Then
MsgBox strValidate
Cancel = True
End If

End Sub


So how do i combine these codes and have the ADD button to show the validation message before adding anything??

I dont want the add button to anything until the form is complete??
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 23:17
Joined
Sep 12, 2006
Messages
15,614
what actually happens at the moment if you have an invalid record?

because your add button tries to do a gotonewrec, the current record will automatically try to save, and therefore it will fire the before update event.

does that mean your gotonewrec event fails because the update fails, or the update fails, and you still go to the newrec?

---------------------
the thing is the add button is not actually ADDING the record - if you have a bound form, the record is already added as soon as you start typing into any field (the access add event is actually the insert event - see beforeinsert and afterinsert) when you move off the record by navigation buttons, recordselectors, or as in your case, moving the recordset cursor, access just saves the current record (if its dirty) now the beforeupdate and afterupdate events fire.

so, if you have a partially completed record and the save fails, you need to decide whether you want to scrap the changes with me.undo as Bob suggested (which you MAY not be able to do in a before-update event - i'm not sure) or prompt the user to complete the changes.

as i said you can trap the error you are seeing in the forms error event handler, and disregard that particular error number (which unfortunately you can't see at the moment because the access error handler doesn't show you the error number!)

.... so you need your own error handler anyway to clarify the error code, because you may want to disregard some errors, but not others!
 

Beany

Registered User.
Local time
Today, 23:17
Joined
Nov 12, 2006
Messages
155
What happens at the moment is that it adds an invalid record

Code:
because your add button tries to do a gotonewrec, the current record will automatically try to save, and therefore it will fire the before update event.

it saves straight away as I type in, whether i click on the add button or not...


PHP:
does that mean your gotonewrec event fails because the update fails, or the update fails, and you still go to the newrec?

the event doesnt fail ( i dont think ) it updates the table even with incomplete form

To be honest I do not understand the concepts of bound and unbound? Whats the difference and how do I change it from one to another?

il try to make it clear for you:

i want an add button that will assess the form before adding it... it should assess if its complete. If incomplete it should show the validation. before adding it should also show a message such as 'are you sure want to add this record'.

Also i should be able to select 'x' and exit the form even if the forms incomplete without any error or validation messages!!!??

the add button adds the rec no matter what.....
 
Last edited:

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 23:17
Joined
Sep 12, 2006
Messages
15,614
do you get your validation error message in the before update event displaying, and then the record saves anyway?

does this mean we have 2 problems then
1. saving incomplete records

2. the close form message
 

Beany

Registered User.
Local time
Today, 23:17
Joined
Nov 12, 2006
Messages
155
PHP:
do you get your validation error message in the before update event displaying, and then the record saves anyway?

does this mean we have 2 problems then

1. saving incomplete records

2. the close form message

the validation error message comes in the before update event of the form.....
its not connected with the add button....

i do have 2 probs: saving incomplete form and closing the form!

sorry for all this bother
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 23:17
Joined
Sep 12, 2006
Messages
15,614
sorry, just trying to get this clear

ignore the close button for the moment

if you click the add button, and the record is incomplete, you should get the validation error message in the beforeupdate event.

Does that happen?

Even if you get the error message, does the record get saved nevertheless, and you then goto the newrecord?
 

Beany

Registered User.
Local time
Today, 23:17
Joined
Nov 12, 2006
Messages
155
The validation message is set on the form, so it only shows when i click the 'x'.

the add doesnt have an before update event (or am i missing sumat?)

ive added the the validation code to the forms before update event.


shall i insert my validation code into the ADD REC code?
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 23:17
Joined
Sep 12, 2006
Messages
15,614
sorry if this isn't clear
--------------------------------

in the add button code the first statement is

DoCmd.GoToRecord , , acNewRec

this will cause the current record to be updated first, before access can take you to the new record. This update will cause the beforeupdate event to be triggered,even though you are not explicitly calling it.

There is in fact a long sequece of events that takes place on virtually any action. Access help can show you the event sequence. What the event handlers we do is select certain of these events and add our own processes to those events. The events occur whether we have code for them or not.

now
a) if you have a valid record you will have no problems

but
b) if you don't have a valid record, you should therefore get your validation message from your before update event code.

what i am not sure of, is if you do get a validation message, whether the record is still saved, although it is incomplete, and you goto the new record, or whether you are unable to go to the new record

----------------
I think we need to clarify exactly what is happening before deciding how to address it.

----------------
the close event is causing a similar sequence to occur, without moving to a new record
 

Beany

Registered User.
Local time
Today, 23:17
Joined
Nov 12, 2006
Messages
155
OK Gemma hun,

im using the following code:

Private Sub addrec_Click()
On Error GoTo Err_addrec_Click

DoCmd.GoToRecord , , acNewRec

Dim blnValidation As Boolean
Dim strValidate As String

strValidate = "These item(s) were not filled out and are required:" & vbCrLf & vbCrLf

If IsNull(Me.username) Or Me.username = "" Then
blnValidate = True
strValidate = strValidate & "Username" & vbCrLf
End If

If IsNull(Me.number) Or Me.number = "" Then
blnValidate = True
strValidate = strValidate & "Number" & vbCrLf
End If

If blnValidate Then
MsgBox strValidate
Cancel = True
End If

Exit_addrec_Click:
Exit Sub

Err_addrec_Click:
MsgBox Err.Description
Resume Exit_addrec_Click

End Sub



The outcomes when i do the following:

EMPTY FORM then click ADD button -----> nothing adds (gud)

INCOMPLETE FORM then click ADD button -------> shows validation and add the record :)( )

COMPLETE FORM then click ADD button --------> shows validation and adds the record:)( )


lol my database is going bonkers! :eek:
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 23:17
Joined
Sep 12, 2006
Messages
15,614
that code won't compile properly - you can't just use the before update code, and paste it in the addrec click event.

1. you are referring to cancel which is not declared in the sub
2. you have declared blnvalidation, but refer to it as blnvalidate

----------------

i don't think i can explain this any more - i think the problem is caused because the actions you are processing are generating errors, but are not forcing the errors to be fixed.

i think therefore it is concerned with the gotonewrec instruction, and you need someway of exiting the code before running that command, if the before update is cancelled
 

Users who are viewing this thread

Top Bottom