A silly problem! :) (1 Viewer)

Beany

Registered User.
Local time
Today, 03:55
Joined
Nov 12, 2006
Messages
155
Hi fellas,

thanks for all ur help in my previous posts.......

ive got this problem, ive got a form that provides mobile details.

on the same form theres an add button and clear button.

all the validations work....... if the forms incomplete then validations do occur.

but the problem is......... if i clear the form (clickin on the clear button) and click 'x' to exit, it brings up one validation, which is the date_issued field validation????? and then exits

why does this validation occur??? how do i get rid of it.............

i want it to exit without any problem....... becoz i have cleared the form
 

BarryMK

4 strings are enough
Local time
Today, 03:55
Joined
Oct 15, 2002
Messages
1,350
Two things that would help people to help you.
1. Type a meaningful title to your request Such as "date validation error" so people here can quickly decide if they can help. Your "Silly problem" could be anything.
2. Give them a clue - post some code.
 

Beany

Registered User.
Local time
Today, 03:55
Joined
Nov 12, 2006
Messages
155
sorry barry,

you must have fell out the wrong side of your bed today :) :)

ok the code i have:

clear button:

Private Sub Command25_Click()
Dim intResponse As Integer

intResponse = MsgBox("Are you sure you want to clear all entries?", vbYesNo, Change)

If intResponse = 6 Then
Me.number.Value = " "
Me.username.Value = " "
Me.cost_centre.Value = " "
Me.phone_model.Value = " "
Me.imei.Value = " "
Me.sim_no.Value = " "
Me.puk_code.Value = " "
Me.date_issued.Value = Null
Me.notes.Value = " "
Me.tariff.Value = " "
Me.roam.Value = False
Me.call_int.Value = False

Else

End If

End Sub



the code for the validation is:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim blnValidation As Boolean
Dim strValidate As String

If IsNull(Me.date_issued) Or Me.date_issued = "" Then
blnValidate = True
strValidate = strValidate & "Date Issued" & vbCrLf
End If
 

seth_belgium

WoW-Addict
Local time
Today, 04:55
Joined
Oct 4, 2005
Messages
175
First you do:

Me.date_issued.Value = Null

and then the validation kicks in (beforeupdate)

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim blnValidation As Boolean
Dim strValidate As String

If IsNull(Me.date_issued) Or Me.date_issued = "" Then
blnValidate = True
strValidate = strValidate & "Date Issued" & vbCrLf
End If

That's why... Working as intended?
 

Beany

Registered User.
Local time
Today, 03:55
Joined
Nov 12, 2006
Messages
155
Seth ive tried your way but it doesnt work..............

ive got a clear button that clears the form but after clearing the form and clicking 'x' it only shows one validation 'date issued'.

i have many more validations, but why does it only show the one 'date_issued'. It shouldnt show this...............

apart from Null is there anything else i can use for the date???
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 03:55
Joined
Sep 12, 2006
Messages
15,692
the problem is, is that clearing the form merely sets the fields for the current record to blank values.

your form STILL has the record which it tries to save, and the validation causes the save to fail, hence your message.

the clear using your method would only work with an unbound form, where you add new records via a recordset (say)

you ought to use an undo command, not the clears

something like

if me.newrecord then docmd.undo 'to clear the newrecord
 

Beany

Registered User.
Local time
Today, 03:55
Joined
Nov 12, 2006
Messages
155
the following code is used for adding new users:

Private Sub addrec_Click()
On Error GoTo Err_addrec_Click

If Me.NewRecord Then DoCmd.Undo


Exit_addrec_Click:
Exit Sub

Err_addrec_Click:
MsgBox Err.Description
Resume Exit_addrec_Click

End Sub


and i am using the following code for validation:

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


the next code is for the clear button:

Private Sub Command25_Click()
Dim intResponse As Integer

intResponse = MsgBox("Are you sure you want to clear all entries?", vbYesNo, Change)

If intResponse = 6 Then
Me.number.Value = " "
Me.username.Value = " "
Me.cost_centre.Value = " "
Me.phone_model.Value = " "
Me.imei.Value = " "
etc etc

WHERE AM I GOING WRONG? I CANT GET RID OF THE NOT NEEDED VALIDATION
 

BarryMK

4 strings are enough
Local time
Today, 03:55
Joined
Oct 15, 2002
Messages
1,350
Beany said:
sorry barry,

you must have fell out the wrong side of your bed today :) :)
Not at all. Like me, when you post a question, you would like a reply to point you in the right direction. It's only polite to post in a manner that helps those who give their time and expertise freely.

I note that posting your code actually elicited responses from the experts here.;) I should also add that the first post I ever made here was of the "Help please" variety.
 
Last edited:

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 03:55
Joined
Sep 12, 2006
Messages
15,692
the clear button is merely clearing the data in the new record -this still leaves a dirty new record, which is not the same thinig as the undo method.
 

Beany

Registered User.
Local time
Today, 03:55
Joined
Nov 12, 2006
Messages
155
barry, if you was to check my first post,im pretty sure it wudnt be hard finding a 'please' in there!!!!

anyway away from the playground, emma thanks for ur info.......

emma do u have (please) any example i can look at?

or can u expand on the 'undo method'??
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 03:55
Joined
Sep 12, 2006
Messages
15,692
instead of all the clears just do

if intresponse =6 then
docmd.undo
end if

undo cancels all changes, and restores the record to its original state before you started typing into it. in the case of a newrecord this DEFINITELY gives you a blank new record. Do you have record selectors on your form. If not put them there to see. The record sleector will change form a black triangle to a pencil when a record has been edited. You will see that your method of clearing the data still leaves a pencil there, as an edited record, but the undo method should reset the pencil to a black triangle.

As soon as you change a record at all the triangle changes to a pencil. You can click the pencil to save the record incidentally.

Hope this helps


by the way, do you really type 6 into the input box? it doesn't sound very user-friendly (or is 6 the response yes. in that case its probably clearer to use the vbconstant vbyes as in

if intresponse=vbyes
 
Last edited:

Beany

Registered User.
Local time
Today, 03:55
Joined
Nov 12, 2006
Messages
155
thanks gemma,

6 does the job! :) why fix sumat when it aint broke? im jokin

im gona try ur way!

cheers
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 03:55
Joined
Sep 12, 2006
Messages
15,692
so is it working now ok? were you able to see the difference between undo-ing the record and merely setting the all the fields to blanks?
 

Beany

Registered User.
Local time
Today, 03:55
Joined
Nov 12, 2006
Messages
155
gemma hun,

im using the following code now:

Private Sub Command25_Click()
Dim intResponse As Integer

intResponse = MsgBox("Are you sure you want to clear all entries?", vbYesNo, Change)

If intResponse = 6 Then
DoCmd.Undo
End If

End Sub


but im getting an error message: Method or data member not found??


am i doing sumat obviously wrong here?
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 03:55
Joined
Sep 12, 2006
Messages
15,692
sorry - thought i'd seen undo before, but that isnt the the right syntax

try instead

application.RunCommand acCmdUndo

[or me.undo, as colin has just pointed out, with the correct syntax!]
 
Last edited:

ColinEssex

Old registered user
Local time
Today, 03:55
Joined
Feb 22, 2002
Messages
9,125
Put the word "change" in quotes.

Use the code

Code:
Me.Undo

Col
 

BarryMK

4 strings are enough
Local time
Today, 03:55
Joined
Oct 15, 2002
Messages
1,350
Beany said:
barry, if you was to check my first post,im pretty sure it wudnt be hard finding a 'please' in there!!!!

anyway away from the playground, QUOTE]

You'd be closer to it than I am.....
 

seth_belgium

WoW-Addict
Local time
Today, 04:55
Joined
Oct 4, 2005
Messages
175
Anyway, like I always say: Show me the problem and then i'll fix it.

Please post your database. ^^
 

Beany

Registered User.
Local time
Today, 03:55
Joined
Nov 12, 2006
Messages
155
sorry i cant not post the database as it has confidential information. im gonna try gemmas and colins ideas..............
 

Users who are viewing this thread

Top Bottom