incorrect syntax near the keyword 'between'

G

Guest

Hi, I'm working on an Access Project (front end) with MSDE (back end). I've
created a search form to open reports. I need to create a Where clause to let
the user enter two values: between ---- And ----
I'm getting an "incorrect syntax near the keyword 'between'.

part of the code goes:
Dim varWhere As Variant
'Initialize to Null
varWhrere = Null

If (Me![SSForms] = 1) Then
DocName = "WWDW_Sample_Submission"
If Not IsNothing(Me.StartID) Then
'.. build the predicate
varWhere = "[LabID]=" & "Between " & Me.[StartID] & "AND " & Me.[ToID]

End If

If (Button = "print") Then
DoCmd.OpenReport DocName, A_NORMAL
Else
DoCmd.OpenReport DocName, A_PREVIEW, WhereCondition:=varWhere
End If

Any help will be greatly appreciated,
 
D

Douglas J. Steele

You don't use = and Between together.

varWhere = "[LabID] Between " & Me.[StartID] & "AND " & Me.[ToID]
 
G

Guest

Thanks so much Douglas! As you can see I'm learning.
Can I bother you with one more question? How can I add the order so when
opening the report is by LabID asc?
Thanks in advance
--
gaba :)


Douglas J. Steele said:
You don't use = and Between together.

varWhere = "[LabID] Between " & Me.[StartID] & "AND " & Me.[ToID]


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



gaba said:
Hi, I'm working on an Access Project (front end) with MSDE (back end).
I've
created a search form to open reports. I need to create a Where clause to
let
the user enter two values: between ---- And ----
I'm getting an "incorrect syntax near the keyword 'between'.

part of the code goes:
Dim varWhere As Variant
'Initialize to Null
varWhrere = Null

If (Me![SSForms] = 1) Then
DocName = "WWDW_Sample_Submission"
If Not IsNothing(Me.StartID) Then
'.. build the predicate
varWhere = "[LabID]=" & "Between " & Me.[StartID] & "AND " & Me.[ToID]

End If

If (Button = "print") Then
DoCmd.OpenReport DocName, A_NORMAL
Else
DoCmd.OpenReport DocName, A_PREVIEW, WhereCondition:=varWhere
End If

Any help will be greatly appreciated,
 
G

Guest

Open the report in design view, in the menu bar select view > sorting and
grouping, Select the field you want to sort by and then select Asc

--
I hope that helped
Good luck


gaba said:
Thanks so much Douglas! As you can see I'm learning.
Can I bother you with one more question? How can I add the order so when
opening the report is by LabID asc?
Thanks in advance
--
gaba :)


Douglas J. Steele said:
You don't use = and Between together.

varWhere = "[LabID] Between " & Me.[StartID] & "AND " & Me.[ToID]


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



gaba said:
Hi, I'm working on an Access Project (front end) with MSDE (back end).
I've
created a search form to open reports. I need to create a Where clause to
let
the user enter two values: between ---- And ----
I'm getting an "incorrect syntax near the keyword 'between'.

part of the code goes:
Dim varWhere As Variant
'Initialize to Null
varWhrere = Null

If (Me![SSForms] = 1) Then
DocName = "WWDW_Sample_Submission"
If Not IsNothing(Me.StartID) Then
'.. build the predicate
varWhere = "[LabID]=" & "Between " & Me.[StartID] & "AND " & Me.[ToID]

End If

If (Button = "print") Then
DoCmd.OpenReport DocName, A_NORMAL
Else
DoCmd.OpenReport DocName, A_PREVIEW, WhereCondition:=varWhere
End If

Any help will be greatly appreciated,
 
G

Guest

Thanks so much Ofer,
Everything working!
--
gaba :)


Ofer said:
Open the report in design view, in the menu bar select view > sorting and
grouping, Select the field you want to sort by and then select Asc

--
I hope that helped
Good luck


gaba said:
Thanks so much Douglas! As you can see I'm learning.
Can I bother you with one more question? How can I add the order so when
opening the report is by LabID asc?
Thanks in advance
--
gaba :)


Douglas J. Steele said:
You don't use = and Between together.

varWhere = "[LabID] Between " & Me.[StartID] & "AND " & Me.[ToID]


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



Hi, I'm working on an Access Project (front end) with MSDE (back end).
I've
created a search form to open reports. I need to create a Where clause to
let
the user enter two values: between ---- And ----
I'm getting an "incorrect syntax near the keyword 'between'.

part of the code goes:
Dim varWhere As Variant
'Initialize to Null
varWhrere = Null

If (Me![SSForms] = 1) Then
DocName = "WWDW_Sample_Submission"
If Not IsNothing(Me.StartID) Then
'.. build the predicate
varWhere = "[LabID]=" & "Between " & Me.[StartID] & "AND " & Me.[ToID]

End If

If (Button = "print") Then
DoCmd.OpenReport DocName, A_NORMAL
Else
DoCmd.OpenReport DocName, A_PREVIEW, WhereCondition:=varWhere
End If

Any help will be greatly appreciated,
 

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

Top