VBA error using Access

Q

QHills

When I type (Me.Charge1 = "11:131(A), 11:131A(2)") And IsNull(Me.Speed1) =
True Then
DoCmd.CancelEvent
DoCmd.GoToControl "Speed1"
returnvalue = MsgBox("A speed must be entered", vbCritical, "Required")
It doesn't give me a message when I don't type in data for Speed1. What is
the problem?
 
A

Amery

I had a similar problem with one of my formsin which I was using a combo box.
While it looked like there was no information in the field, it was saving a
default ID for no entry (in my case a zero). I had to set the if statement so
that it read:

If me.combo1=0 then
end if

Hope that this works for you.
 
Q

QHills

This didn't solve my problem. I am placing this code on the form before the
update. So, whenever someone selects from the combo box from any of these
statues(EX.: 11:131A(1), 11:131A(2)) and don't put a speed(Ex.: 50)in the
next field, it will display an error message, when they try to proceed to the
next record. Is there anything else I can do?
 
K

Kevin K. Sullivan

You can't use a comma in the way you are trying. You need to use Or to
combine two logical conditions. When you do, make sure you avoid the
beginner mistake of trying:

If A = B Or C Then ...

when you really mean:

If (A = B) Or (A = C) Then ...

Your code never fired because Charge1 was never equal to the literal value:

"11:131(A), 11:131A(2)"



try: (air code), watch line wrap
If (Me.Charge1 = "11:131(A)" OR Me.Charge1 = "11:131A(2)") And
IsNull(Me.Speed1) = True Then

Cancel = True ' if you are inside the BeforeUpdate event,
'just set Cancel = True. No need for CancelEvent
Me.Speed1.SetFocus
returnvalue = MsgBox("A speed must be entered", vbCritical, "Required")
End If



HTH,
 
Q

QHills

I figured it out before you responded;however, I thank you for your output.
Now, I have another question. Since, my conditional statement will be pretty
long is there anyway that I can add code to the next line without it giving
me a complie error "Expected Then".
 
K

Kevin K. Sullivan

Line continuation characters:

If you place an underscore as the last character in a line, the next
line is considered a continuation of the same line

---

If (SituationA = True) And (Sentence = "Lock that lead-foot up") And _
(Speed1 > 80) And (ASDF = False) And (Field39 = False) And _
(Field62 > 0) Then
----

if the text that breaks is a string literal, you need to break it into
two pieces and use & to patch it back together
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Error 2001 1
Error 2001 0
Error 2001 0
Error 2001 0
Error 2001 message 1
VSTO C# add in Outlook.Appointment error 0
How to validate data in a field? 3
type mismatch error in macro in excel 0

Top