help with code - newby

  • Thread starter Thread starter Steve Goodrich
  • Start date Start date
S

Steve Goodrich

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
 
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

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?
 
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
 
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

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.
 
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


fredg said:
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

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.
 
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

fredg said:
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

On Tue, 13 May 2008 21:18:21 GMT, Steve Goodrich wrote:

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

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?

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.

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.
 
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
fredg said:
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

fredg said:
On Wed, 14 May 2008 21:03:37 GMT, Steve Goodrich wrote:

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

On Tue, 13 May 2008 21:18:21 GMT, Steve Goodrich wrote:

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

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?
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail

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.

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.
 
Back
Top