Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / New Users / May 2008

Tip: Looking for answers? Try searching our database.

help with code - newby

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steve Goodrich - 13 May 2008 22:18 GMT
I have a check box on my form that I want a message box to pop up if the
check box is not ticked when the form is submitted.

I've done this before but it was a while ago and I've forgot!

If I recall it was something like:

If me.fieldname = false then
msgbox "please check box"
end if

obviously I've remembered it wrong because it doesn't work.

Also does it go in the before or after update section

Thanks for any help

Steve
fredg - 13 May 2008 23:04 GMT
> I have a check box on my form that I want a message box to pop up if the
> check box is not ticked when the form is submitted.
[quoted text clipped - 14 lines]
>
> Steve

Code the Form's BeforeUpdate event:

If Me.CheckBoxName = 0 then
    MsgBox = "You must check the check box."
    Cancel = True
End If

But it the check box must always be checked, why not just set it's
default to -1 and not bother the user with it,
or... if it always needs to be checked why have it at all?
Signature

Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail

Steve Goodrich - 14 May 2008 22:03 GMT
Hi Fred

I'm still not able to do this. Don't know what I'm doing wrong.
I copied and pasted your text into the before update event on my form and
changed the name of the checkbox to my own, but I am still allowed to enter
a record and go to the next record without the message box popping up.

Basically the check box serves as a reminder to staff that they have
completed another task before submitting the record

Steve

>> I have a check box on my form that I want a message box to pop up if the
>> check box is not ticked when the form is submitted.
[quoted text clipped - 25 lines]
> default to -1 and not bother the user with it,
> or... if it always needs to be checked why have it at all?
fredg - 14 May 2008 22:43 GMT
> Hi Fred
>
[quoted text clipped - 37 lines]
>> default to -1 and not bother the user with it,
>> or... if it always needs to be checked why have it at all?

When something like this occurs it's always useful for you to post the
complete code you actually wrote (including the Sub Procedure name).
That way we can see what you actually did, not what you say you did.
Sometimes there is a BIG difference. :-) Nothing personal with the
comment. Just a helpful hint.

It works for me. Here is the entire event code I used.
Note.... In my previous reply I inadvertently wrote
MsgBox = " etc.."
when I should have written
MsgBox " etc..."  (no = sign)

The below code is correct.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.[Check] = 0 Then
    MsgBox "You must check the check box."
    Cancel = True
End If
End Sub

Change [Check] to the actual name of your check box
Make sure it's in the FORM's BeforeUpdate event, not of a control on
the form.

Signature

Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail

Steve Goodrich - 14 May 2008 22:59 GMT
Hi Fred
Tried it without the = but still no joy

my check box is called test
here is the code

Private Sub Test_BeforeUpdate(Cancel As Integer)
If Me.Test = 0 Then
MsgBox "You must check the check box."
Cancel = True
End If
End Sub

>> Hi Fred
>>
[quoted text clipped - 64 lines]
> Make sure it's in the FORM's BeforeUpdate event, not of a control on
> the form.
fredg - 14 May 2008 23:31 GMT
> Hi Fred
> Tried it without the = but still no joy
[quoted text clipped - 77 lines]
>> Make sure it's in the FORM's BeforeUpdate event, not of a control on
>> the form.

Steve,
Did you not read this line of my response?

Make sure it's in the FORM's BeforeUpdate event, not of a control on
the form.

It seems that Test is the name of the check box field.
The form also has a BeforeUpdate event. That's where the code goes.
When you place your code in the Form's BeforeUpdate event, the actual
name of the event is exactly as I wrote it in the previous message.
Here is the full code using YOUR check box name.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Test = 0 Then
MsgBox "You must check the check box."
Cancel = True
End If
End Sub

Don't change anything. Just write it in the Form's BeforeUpdate
event, not in the Test control's BeforeUpdate event.

Signature

Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail

Steve Goodrich - 15 May 2008 00:09 GMT
Fred,
Many thanks, works perfectly. I'm finding this side of access very difficult
not coming from a technical background.
Thanks for your patience.
Steve

>> Hi Fred
>> Tried it without the = but still no joy
[quoted text clipped - 100 lines]
> Don't change anything. Just write it in the Form's BeforeUpdate
> event, not in the Test control's BeforeUpdate event.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.