Fantastic
But I have one last question: I also need to see all the data if both combo
boxes are left blank. Presently, if they are left blank there is no data is
returned.
I cannot thank you enough, I have three databases that have been in need if
this capability..
This is the code I have, which has no data return if combo boxes are blank.
Answer = MsgBox("Expedited Case??", vbQuestion + vbYesNo, "Question")
If Answer = vbYes Then
stExpedited = "[TR_EXPEDITED]=" & True
Else
stExpedited = "[TR_EXPEDITED]=" & False
End If
If Not (IsNull(Me.cmbstatus)) Then
stCriteria = "[TR_Status]= '" & Me.cmbstatus & "'"
End If
If Not (IsNull(Me.DecCode)) Then
If Len(stCriteria) > 0 Then
stCriteria = stCriteria & " AND "
stCriteria = stCriteria & "[TR_DECISION]= '" & Me.DecCode & "'"
End If
If Len(stCriteria) > 0 Then
stCriteria = stCriteria & " AND "
stCriteria = stCriteria & stExpedited
End If
stDocName = "r_GroupBasic"
DoCmd.OpenReport stDocName, acPreview, , stCriteria
Klatuu said:
First, it is not included in stCriteria
Second, you need to make changes to your code to keep values outside the
quotes.
Third, Be sure that [TR_EXPEDITED] is a Yes/No field in your table.
And, you need to add it to strCriteria
Answer = MsgBox("Expedited Case??", vbQuestion + vbYesNo, "Question")
If Answer = vbYes Then
stExpedited = "[TR_EXPEDITED]= " & True
Else
stExpedited = "[TR_EXPEDITED]= " & False
End If
Now, after you have built the other criteria, just before you open the report"
If len(stCrtiteria) > 0 Then
stCriteria = strCriteria & " AND "
End If
strCriteria = strCriteria & stExpedited
:
I think I'm 99% there - this code returns data based on the answer to the two
combo boxes. BUT, it does not consider the answer to the MsgBox.
The DoCmd shows everything for "stCriteria" but how do I include the
"stExpedited"
Answer = MsgBox("Expedited Case??", vbQuestion + vbYesNo, "Question")
If Answer = vbYes Then
stExpedited = "[TR_EXPEDITED]=True"
Else
stExpedited = "[TR_EXPEDITED]=False"
End If
If Not (IsNull(Me.cmbstatus)) Then
stCriteria = "[TR_Status]= '" & Me.cmbstatus & "'"
If Not (IsNull(Me.DecCode)) Then
If Len(stCriteria) > 0 Then
stCriteria = stCriteria & " AND "
stCriteria = stCriteria & "[TR_DECISION]= '" & Me.DecCode & "'"
End If
End If
stDocName = "r_GroupBasic"
DoCmd.OpenReport stDocName, acPreview, , stCriteria
:
Caught my typo, thanks, actually, it is text and should be:
strCriteria = strCriteria & "[TR_DECISION] = '" & Me.DecCode & "'"
:
The last statement needs to be:
strCriteria = strCriteria & "[TR_DECISION] = Me.DecCode"
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
1. I added the space after AND.
2. [TR_DECISION] and [S_STATUS] are both text fields.
3. I had noticed the stCriteria and changed it in the OpenReport.
The first IF works fine, even if I change the fields to decision, I will
get
the correct decision:
If Not (IsNull(Me.cmbstatus)) Then
stCriteria = "[TR_STATUS]= '" & Me.cmbstatus & "'
The problem seems to be in the second IF, the results completly ecnore
this
combo box and the return is all of them.
If Not (IsNull(Me.DecCode)) Then
If Len(strCriteria) > 0 Then
strCriteria = strCriteria & " AND "
strCriteria = "[TR_DECISION] = Me.DecCode"
HELP
:
Change " AND" to " AND " It should have a space after it.
Be sure [TR_DECISION] is a text field
Be sure [S_STATUS] is a numeric field
The other part is probably my fault. I used stCriteria, which you
copied;
however, your open report may still be using stLinkCriteria. Be sure
the
variable name you are using to build the Where string is the same you
are
using in the OpenReport.
:
You have me going in the right direction, but I am getting a data
return of
all records, not just the ones specific to the combo boxes.
Here are the combinations I have tried:
A.
If Not (IsNull(Me.DecCode)) Then
stCriteria = "[TR_DECISION]='" & Me.DecCode & "'"
End If
If Not (IsNull(Me.cmbstatus)) Then
If Len(strCriteria) > 0 Then
strCriteria = strCriteria & " AND"
End If
strCriteria = strCriteria & "[S_STATUS] = Me.cmbstatus"
End If
Results: I get results but not specific to the combo boxes..
B.
If Not (IsNull(Me.cmbstatus)) Then
stCriteria = "[TR_STATUS]='" & Me.cmbstatus & "'"
End If
If Not (IsNull(Me.DecCode)) Then
If Len(strCriteria) > 0 Then
strCriteria = strCriteria & " AND"
strCriteria = "[TR_DECISION] = Me.DecCode"
End If
End If
Results: Same as A.
:
I' having a little trouble understanding your code. I notice you
are adding
stexpedited to more than one field. Can you tell me how stexpedited
really
works. The syntax below has stExpedited after the word AND with no
comparision.
Another problem is you are adding " AND " to stLink Critera without
knowing
whether you will be adding any other criteria.
If Not (IsNull(Me.InqType)) Then
stLinkCriteria = "[TR_INQUIRYTYPE]=" & "'" & Me.InqType & "' AND
"
& stExpedited
Normally, if you are building a Where String it would be something
like:
If Not IsNull(Me.FirstCombo) Then
strCriteria = "[SomeField] = '" & Me.FirstCombo & "'"
End If
If Not isNull(Me.SecondCombo) Then
If Len(strCriteria) > 0 Then
strCriteria = strCriteria & " AND"
End If
strCriteria = strCriteria & "[AnotherField] = "Me.SecondCombo"
End If
:
Ok, although I learned alot from the reading, I still cannot get
it to do
what I need.
Let me re-ask my question in it's simpliest form:
One command button.
Three Combo boxes.
Could you please show me the simpliest code, when I click the
command
button, it returns the choices made from the 3 combo boxes.
If I can understand this I will be able to tweek it from there,
for what I
need.
Thank you for the help.
:
The "tick marks" would be correct provided [TR_EXPEDITED] is a
boolean data
type.
I don't know what you mean by "get no return" With a list box,
you have to
use the ItemsSelected collection and handle each selected item
independantly.
Read up on the ItemsSelected property in VBA Help.
:
Ok, I did that and I can select a list of items, but I get no
return of
anything when I click it... Here is my code - please see my
note about 1/2
way down....
Dim stDocName As String
Dim stLinkCriteria As String
Dim Answer As String
Dim stExpedited As String
If IsNull(Me.StartDate) Or IsNull(Me.EndDate) Then
MsgBox "You must enter a Start & Stop date."
Else
Answer = MsgBox("Expedited Case??", vbQuestion + vbYesNo,
"Question")
If Answer = vbYes Then
stExpedited = "[TR_EXPEDITED]=True"
Else
stExpedited = "[TR_EXPEDITED]=False"
End If
'If Not (IsNull(Me.InqType)) Then
' stLinkCriteria = "[TR_INQUIRYTYPE]=" & "'" &
Me.InqType & "' AND "
& stExpedited
'''' If I remove the ticks above and put them below (for
status) the job works
If Not (IsNull(Me.status)) Then
stLinkCriteria = "[TR_STATUS]=" & "'" & Me.status & "'
AND " &