Should not be to hard of a question (1 Viewer)

Cpar

Registered User.
Local time
Today, 15:06
Joined
Jan 9, 2016
Messages
41
I am having trouble with vba code for between. Such as if this box has a value within .11 and .25 then return "different control source" with "A". Like I said should be a simple enough question. I do not know why I can not get it. Thanks in advance
 

CJ_London

Super Moderator
Staff member
Local time
Today, 20:06
Joined
Feb 19, 2013
Messages
16,553
between do not work in vba - use >= and <= e,g,

myvalue>=x and myvalue<=y
 

yupstrips01

Registered User.
Local time
Tomorrow, 01:36
Joined
Mar 31, 2016
Messages
19
thanks for sharing this post, its helping me
 

isladogs

MVP / VIP
Local time
Today, 20:06
Joined
Jan 14, 2017
Messages
18,186
between do not work in vba - use >= and <= e,g,

myvalue>=x and myvalue<=y

Sorry but this isn't true
The following 2 SQL statements do EXACTLY the same thing

Code:
DoCmd.RunSQL "UPDATE SchConstants SET SchConstants.[Value] = Null" & _
        " WHERE (((SchConstants.ConstantID) Between 76 And 81));"

Code:
DoCmd.RunSQL "UPDATE SchConstants SET SchConstants.[Value] = Null" & _
        " WHERE (((SchConstants.ConstantID)>=76 And (SchConstants.ConstantID)<=81));"

I find the first version easier to use and less typing!
 

CJ_London

Super Moderator
Staff member
Local time
Today, 20:06
Joined
Feb 19, 2013
Messages
16,553
this is an old question, but it was not to do with writing a sql statement in VBA (in which case I agree with you) but using VBA e.g.

if X between 1 and 3 then...
 

isladogs

MVP / VIP
Local time
Today, 20:06
Joined
Jan 14, 2017
Messages
18,186
Hi Chris

I responded when the thread was resurrected by rebeccajr
EDIT: rebeccajr's posts have since been deleted...! :D

Anyway - that wasn't how I read the thread.
You are of course absolutely correct for IF statements

This works
Code:
If X>=1 And X<=5 Then MsgBox "The value of X = " & X

but this doesn't
Code:
If X Between 1 And 5 Then MsgBox "The value of X = " & X

Cheers ;)
 
Last edited:

Users who are viewing this thread

Top Bottom