Multi options

D

Douglas J. Steele

There's a closing parenthesis in the wrong place:

strWhere = " WHERE " & Left$(strWhere, Len(strWhere) - 5)


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Dan @BCBS said:
That certainly was an over sight on my part.
But even so, I get the same error message at: (strWhere - 5))
Dim stDocName As String
Dim strWhere As String
Dim strWhere1 As String
Dim strWhere2 As String
Dim strWhere3 As String


stDocName = "Report1"

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please make sure you entered a start and end date."
Exit Sub
Else

strWhere1 = [lstArea]
strWhere2 = [lstProduct]
strWhere3 = [cboReviewer]

If Len(strWhere1) > 0 Then
strWhere = strWhere & strWhere1 & " AND "
End If

If Len(strWhere2) > 0 Then
strWhere = strWhere & strWhere2 & " AND "
End If

If Len(strWhere3) > 0 Then
strWhere = strWhere & strWhere3 & " AND "
End If

If Len(strWhere) > 0 Then
strWhere = " WHERE " & Left$(strWhere, Len(strWhere - 5))
End If

//////////////////////////////////


Douglas J. Steele said:
You've declared strWhere as an Integer, but you're trying to assign a
String
to it.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Dan @BCBS said:
I've simplified the code to only pull in one value if entered.
The only error I get is a popup saying "13 Type Mismatch"
Any idea what that means???
Or at what point in my code to correct??

Private Sub cmdKey_Click()
On Error GoTo Err_cmdKey_Click
Dim stDocName As String
Dim strWhere As Integer
Dim strWhere3 As Integer

stDocName = "rptQualityAuditList"
strReport = "Audit"

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please enter a start and end date to run this report."
Exit Sub
Else

strWhere3 = [cboReviewer]

If Len(strWhere3) > 0 Then
strWhere = strWhere & strWhere3 & " AND "
End If


stStart = Me.txtStart
stEnd = Me.txtEnd

'DoCmd.SendObject acReport, stDocName, acFormatRTF, , , , , ,
True
DoCmd.OpenReport stDocName, acPreview
End If

:

Your code below answers a lot of questions and makes what I've been
trying to
accomplish it look simple.
But your last "If" confuses me, I don't see how all 3 values are
passed
to
"strWhere" or what it does?
My 3 values are "lstArea","lstProduct" and "cboReviewer"

So here is what a I did. It bombs at the end: Len(strWhere - 5 :

Dim strWhere As Integer
Dim strWhere1 As Integer
Dim strWhere2 As Integer
Dim strWhere3 As Integer


stDocName = "rptQualityAuditList"
strReport = "Audit"

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please enter a start and end date to run this report."
Exit Sub
Else

strWhere1 = [lstArea]
strWhere2 = [lstProduct]
strWhere3 = [cboReviewer]

If Len(strWhere1) > 0 Then
strWhere = strWhere & strWhere1 & " AND "
End If
If Len(strWhere2) > 0 Then
strWhere = strWhere & strWhere2 & " AND "
End If
If Len(strWhere3) > 0 Then
strWhere = strWhere & strWhere3 & " AND "
End If

If Len(strWhere) > 0 Then
strWhere = " WHERE " & Left$(strWhere, Len(strWhere - 5))
End If


Thanks







:

You've already got an Else in the construction: you can't use ElseIf
once
you've used Else. Not only that, but ElseIf requires a condition to
evaluate:

If condition Then
[statements]
[ElseIf condition-n Then
[elseifstatements] ...
[Else
[elsestatements]]
End If

What I typically do is take each part separately. For example, I'll
define
variables strWhere1, strWhere2 and strWhere3, as well as an overall
strWhere. I'll then have a section of code that possible defines
strWhere1,
or leaves it blank if there isn't anything applicable to that
condition.
Similarly, I'll either define strWhere2 and strWhere3, or leave them
blank,
depending on the fields on the form.

Once I've done all that, I'll complete the Where clause by checking
the
values of each of the variables:

If Len(strWhere1) > 0 Then
strWhere = strWhere & strWhere1 & " AND "
End If
If Len(strWhere2) > 0 Then
strWhere = strWhere & strWhere2 & " AND "
End If
If Len(strWhere3) > 0 Then
strWhere = strWhere & strWhere3 & " AND "
End If

If Len(strWhere) > 0 Then
strWhere = " WHERE " & Left$(strWhere, Len(strWhere - 5))
End If



--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I tried using "ElseIf" and just duplicate the X-value.
Could you look at this to see why it will not allow an "ElseIf"
(Note: These values are Public
Public stStart As String
Public stEnd As String
Public stAreaList As String
Public stRevList As String)


Dim stDocName As String
Dim X As Integer
Dim Y As Integer
Dim stArea As Variant
Dim stReviewer As Variant

stDocName = "rptQualityAuditList"
strReport = "Audit"

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please enter a start and end date to run this
report."
Exit Sub
Else
X = 0
For Each stArea In lstArea.ItemsSelected
If X = 0 Then
stAreaList = "In('" & lstArea.ItemData(stArea) &
"'"
Else
stAreaList = stAreaList & ",'" &
lstArea.ItemData(stArea) &
"'"
End If
X = X + 1
Next stArea

stAreaList = stAreaList & ")"

ElseIf

Y = 0
For Each stReviewer In cboReviewer.ItemsSelected
If Y = 0 Then
stRevList = "In('" &
cboReviewer.ItemData(stReviewer)
& "'"
Else
stRevList = stRevList & ",'" &
cboReviewer.ItemData(cboReviewer) & "'"
End If
Y = Y + 1
Next cboReviewer

stRevList = stRevList & ")"
End If


If stRevList = ")" Then
MsgBox "Please select a Location."

stStart = Me.txtStart
stEnd = Me.txtEnd

Else
'DoCmd.SendObject acReport, stDocName, acFormatRTF, , , , ,
,
True
DoCmd.OpenReport stDocName, acPreview
End If











:

Your suggestions are great/simple but let me expalin why my dates
are
this way:

A. command button- .......strReport = "Audit"...Bla Bla.... to
open
the
report.

B. Report event:
If Forms!frmreportsquality.strReport = "Audit" Then.........

In the Report event, I pull out Distinct data including the dates
entered
at
the beginning on the form that the command button in on.

My Question is - and I'm going back to my original question, how
can
I
add
another value...
This code correctly makes sure the "dates" were entered, also the
"1stArea"
(if 1 or more choices are picked from the list box) and returns
the
proper
data on the report..

*** I need to add the combo box choice called
"cboReviewer".......****

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please enter a start and end date to run this
report."
Exit Sub
Else
X = 0
For Each stArea In lstArea.ItemsSelected
If X = 0 Then
stAreaList = "In('" & lstArea.ItemData(stArea) &
"'"
Else
stAreaList = stAreaList & ",'" &
lstArea.ItemData(stArea)
&
"'"
End If
X = X + 1
Next stArea

stAreaList = stAreaList & ")"
End If






:

stLinkCriteria = "[issueclosedate] between #" & Me.txtStart &
"#
and #"
&
Me.txtEnd & "# And Somefield = " & Me.cboReviewer

That assumes Somefield is a numeric field, and cboReviewer
returns
a
number.
If it's text, you'll need quotes:

stLinkCriteria = "[issueclosedate] between #" & Me.txtStart &
"#
and #"
&
Me.txtEnd & "# And Somefield = " & Chr$(34) & Me.cboReviewer &
Chr$(34)
 
D

Dan @BCBS

I'm getting past (strWhere - 5) But I'm getting an " 94 Invalid Use Of Null"
Even without the ""If IsNull(Me.txtStart) Or...""

??



Douglas J. Steele said:
There's a closing parenthesis in the wrong place:

strWhere = " WHERE " & Left$(strWhere, Len(strWhere) - 5)


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Dan @BCBS said:
That certainly was an over sight on my part.
But even so, I get the same error message at: (strWhere - 5))
Dim stDocName As String
Dim strWhere As String
Dim strWhere1 As String
Dim strWhere2 As String
Dim strWhere3 As String


stDocName = "Report1"

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please make sure you entered a start and end date."
Exit Sub
Else

strWhere1 = [lstArea]
strWhere2 = [lstProduct]
strWhere3 = [cboReviewer]

If Len(strWhere1) > 0 Then
strWhere = strWhere & strWhere1 & " AND "
End If

If Len(strWhere2) > 0 Then
strWhere = strWhere & strWhere2 & " AND "
End If

If Len(strWhere3) > 0 Then
strWhere = strWhere & strWhere3 & " AND "
End If

If Len(strWhere) > 0 Then
strWhere = " WHERE " & Left$(strWhere, Len(strWhere - 5))
End If

//////////////////////////////////


Douglas J. Steele said:
You've declared strWhere as an Integer, but you're trying to assign a
String
to it.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I've simplified the code to only pull in one value if entered.
The only error I get is a popup saying "13 Type Mismatch"
Any idea what that means???
Or at what point in my code to correct??

Private Sub cmdKey_Click()
On Error GoTo Err_cmdKey_Click
Dim stDocName As String
Dim strWhere As Integer
Dim strWhere3 As Integer

stDocName = "rptQualityAuditList"
strReport = "Audit"

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please enter a start and end date to run this report."
Exit Sub
Else

strWhere3 = [cboReviewer]

If Len(strWhere3) > 0 Then
strWhere = strWhere & strWhere3 & " AND "
End If


stStart = Me.txtStart
stEnd = Me.txtEnd

'DoCmd.SendObject acReport, stDocName, acFormatRTF, , , , , ,
True
DoCmd.OpenReport stDocName, acPreview
End If

:

Your code below answers a lot of questions and makes what I've been
trying to
accomplish it look simple.
But your last "If" confuses me, I don't see how all 3 values are
passed
to
"strWhere" or what it does?
My 3 values are "lstArea","lstProduct" and "cboReviewer"

So here is what a I did. It bombs at the end: Len(strWhere - 5 :

Dim strWhere As Integer
Dim strWhere1 As Integer
Dim strWhere2 As Integer
Dim strWhere3 As Integer


stDocName = "rptQualityAuditList"
strReport = "Audit"

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please enter a start and end date to run this report."
Exit Sub
Else

strWhere1 = [lstArea]
strWhere2 = [lstProduct]
strWhere3 = [cboReviewer]

If Len(strWhere1) > 0 Then
strWhere = strWhere & strWhere1 & " AND "
End If
If Len(strWhere2) > 0 Then
strWhere = strWhere & strWhere2 & " AND "
End If
If Len(strWhere3) > 0 Then
strWhere = strWhere & strWhere3 & " AND "
End If

If Len(strWhere) > 0 Then
strWhere = " WHERE " & Left$(strWhere, Len(strWhere - 5))
End If


Thanks







:

You've already got an Else in the construction: you can't use ElseIf
once
you've used Else. Not only that, but ElseIf requires a condition to
evaluate:

If condition Then
[statements]
[ElseIf condition-n Then
[elseifstatements] ...
[Else
[elsestatements]]
End If

What I typically do is take each part separately. For example, I'll
define
variables strWhere1, strWhere2 and strWhere3, as well as an overall
strWhere. I'll then have a section of code that possible defines
strWhere1,
or leaves it blank if there isn't anything applicable to that
condition.
Similarly, I'll either define strWhere2 and strWhere3, or leave them
blank,
depending on the fields on the form.

Once I've done all that, I'll complete the Where clause by checking
the
values of each of the variables:

If Len(strWhere1) > 0 Then
strWhere = strWhere & strWhere1 & " AND "
End If
If Len(strWhere2) > 0 Then
strWhere = strWhere & strWhere2 & " AND "
End If
If Len(strWhere3) > 0 Then
strWhere = strWhere & strWhere3 & " AND "
End If

If Len(strWhere) > 0 Then
strWhere = " WHERE " & Left$(strWhere, Len(strWhere - 5))
End If



--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I tried using "ElseIf" and just duplicate the X-value.
Could you look at this to see why it will not allow an "ElseIf"
(Note: These values are Public
Public stStart As String
Public stEnd As String
Public stAreaList As String
Public stRevList As String)


Dim stDocName As String
Dim X As Integer
Dim Y As Integer
Dim stArea As Variant
Dim stReviewer As Variant

stDocName = "rptQualityAuditList"
strReport = "Audit"

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please enter a start and end date to run this
report."
Exit Sub
Else
X = 0
For Each stArea In lstArea.ItemsSelected
If X = 0 Then
stAreaList = "In('" & lstArea.ItemData(stArea) &
"'"
Else
stAreaList = stAreaList & ",'" &
lstArea.ItemData(stArea) &
"'"
End If
X = X + 1
Next stArea

stAreaList = stAreaList & ")"

ElseIf

Y = 0
For Each stReviewer In cboReviewer.ItemsSelected
If Y = 0 Then
stRevList = "In('" &
cboReviewer.ItemData(stReviewer)
& "'"
Else
stRevList = stRevList & ",'" &
cboReviewer.ItemData(cboReviewer) & "'"
End If
Y = Y + 1
Next cboReviewer

stRevList = stRevList & ")"
End If


If stRevList = ")" Then
MsgBox "Please select a Location."

stStart = Me.txtStart
stEnd = Me.txtEnd

Else
'DoCmd.SendObject acReport, stDocName, acFormatRTF, , , , ,
,
True
DoCmd.OpenReport stDocName, acPreview
End If











:

Your suggestions are great/simple but let me expalin why my dates
are
this way:

A. command button- .......strReport = "Audit"...Bla Bla.... to
open
the
report.

B. Report event:
 
D

Douglas J. Steele

On what line of code is that error occurring?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Dan @BCBS said:
I'm getting past (strWhere - 5) But I'm getting an " 94 Invalid Use Of
Null"
Even without the ""If IsNull(Me.txtStart) Or...""

??



Douglas J. Steele said:
There's a closing parenthesis in the wrong place:

strWhere = " WHERE " & Left$(strWhere, Len(strWhere) - 5)


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Dan @BCBS said:
That certainly was an over sight on my part.
But even so, I get the same error message at: (strWhere - 5))
Dim stDocName As String
Dim strWhere As String
Dim strWhere1 As String
Dim strWhere2 As String
Dim strWhere3 As String


stDocName = "Report1"

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please make sure you entered a start and end date."
Exit Sub
Else

strWhere1 = [lstArea]
strWhere2 = [lstProduct]
strWhere3 = [cboReviewer]

If Len(strWhere1) > 0 Then
strWhere = strWhere & strWhere1 & " AND "
End If

If Len(strWhere2) > 0 Then
strWhere = strWhere & strWhere2 & " AND "
End If

If Len(strWhere3) > 0 Then
strWhere = strWhere & strWhere3 & " AND "
End If

If Len(strWhere) > 0 Then
strWhere = " WHERE " & Left$(strWhere, Len(strWhere - 5))
End If

//////////////////////////////////


:

You've declared strWhere as an Integer, but you're trying to assign a
String
to it.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I've simplified the code to only pull in one value if entered.
The only error I get is a popup saying "13 Type Mismatch"
Any idea what that means???
Or at what point in my code to correct??

Private Sub cmdKey_Click()
On Error GoTo Err_cmdKey_Click
Dim stDocName As String
Dim strWhere As Integer
Dim strWhere3 As Integer

stDocName = "rptQualityAuditList"
strReport = "Audit"

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please enter a start and end date to run this
report."
Exit Sub
Else

strWhere3 = [cboReviewer]

If Len(strWhere3) > 0 Then
strWhere = strWhere & strWhere3 & " AND "
End If


stStart = Me.txtStart
stEnd = Me.txtEnd

'DoCmd.SendObject acReport, stDocName, acFormatRTF, , , , , ,
True
DoCmd.OpenReport stDocName, acPreview
End If

:

Your code below answers a lot of questions and makes what I've been
trying to
accomplish it look simple.
But your last "If" confuses me, I don't see how all 3 values are
passed
to
"strWhere" or what it does?
My 3 values are "lstArea","lstProduct" and "cboReviewer"

So here is what a I did. It bombs at the end: Len(strWhere - 5 :

Dim strWhere As Integer
Dim strWhere1 As Integer
Dim strWhere2 As Integer
Dim strWhere3 As Integer


stDocName = "rptQualityAuditList"
strReport = "Audit"

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please enter a start and end date to run this
report."
Exit Sub
Else

strWhere1 = [lstArea]
strWhere2 = [lstProduct]
strWhere3 = [cboReviewer]

If Len(strWhere1) > 0 Then
strWhere = strWhere & strWhere1 & " AND "
End If
If Len(strWhere2) > 0 Then
strWhere = strWhere & strWhere2 & " AND "
End If
If Len(strWhere3) > 0 Then
strWhere = strWhere & strWhere3 & " AND "
End If

If Len(strWhere) > 0 Then
strWhere = " WHERE " & Left$(strWhere, Len(strWhere - 5))
End If


Thanks







:

You've already got an Else in the construction: you can't use
ElseIf
once
you've used Else. Not only that, but ElseIf requires a condition
to
evaluate:

If condition Then
[statements]
[ElseIf condition-n Then
[elseifstatements] ...
[Else
[elsestatements]]
End If

What I typically do is take each part separately. For example,
I'll
define
variables strWhere1, strWhere2 and strWhere3, as well as an
overall
strWhere. I'll then have a section of code that possible defines
strWhere1,
or leaves it blank if there isn't anything applicable to that
condition.
Similarly, I'll either define strWhere2 and strWhere3, or leave
them
blank,
depending on the fields on the form.

Once I've done all that, I'll complete the Where clause by
checking
the
values of each of the variables:

If Len(strWhere1) > 0 Then
strWhere = strWhere & strWhere1 & " AND "
End If
If Len(strWhere2) > 0 Then
strWhere = strWhere & strWhere2 & " AND "
End If
If Len(strWhere3) > 0 Then
strWhere = strWhere & strWhere3 & " AND "
End If

If Len(strWhere) > 0 Then
strWhere = " WHERE " & Left$(strWhere, Len(strWhere - 5))
End If



--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I tried using "ElseIf" and just duplicate the X-value.
Could you look at this to see why it will not allow an "ElseIf"
(Note: These values are Public
Public stStart As String
Public stEnd As String
Public stAreaList As String
Public stRevList As String)


Dim stDocName As String
Dim X As Integer
Dim Y As Integer
Dim stArea As Variant
Dim stReviewer As Variant

stDocName = "rptQualityAuditList"
strReport = "Audit"

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please enter a start and end date to run this
report."
Exit Sub
Else
X = 0
For Each stArea In lstArea.ItemsSelected
If X = 0 Then
stAreaList = "In('" & lstArea.ItemData(stArea) &
"'"
Else
stAreaList = stAreaList & ",'" &
lstArea.ItemData(stArea) &
"'"
End If
X = X + 1
Next stArea

stAreaList = stAreaList & ")"

ElseIf

Y = 0
For Each stReviewer In cboReviewer.ItemsSelected
If Y = 0 Then
stRevList = "In('" &
cboReviewer.ItemData(stReviewer)
& "'"
Else
stRevList = stRevList & ",'" &
cboReviewer.ItemData(cboReviewer) & "'"
End If
Y = Y + 1
Next cboReviewer

stRevList = stRevList & ")"
End If


If stRevList = ")" Then
MsgBox "Please select a Location."

stStart = Me.txtStart
stEnd = Me.txtEnd

Else
'DoCmd.SendObject acReport, stDocName, acFormatRTF, , , ,
,
,
True
DoCmd.OpenReport stDocName, acPreview
End If











:

Your suggestions are great/simple but let me expalin why my
dates
are
this way:

A. command button- .......strReport = "Audit"...Bla Bla.... to
open
the
report.

B. Report event:
 
D

Dan @BCBS

Douglas J. Steele said:
On what line of code is that error occurring?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Dan @BCBS said:
I'm getting past (strWhere - 5) But I'm getting an " 94 Invalid Use Of
Null"
Even without the ""If IsNull(Me.txtStart) Or...""

??



Douglas J. Steele said:
There's a closing parenthesis in the wrong place:

strWhere = " WHERE " & Left$(strWhere, Len(strWhere) - 5)


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


That certainly was an over sight on my part.
But even so, I get the same error message at: (strWhere - 5))
Dim stDocName As String
Dim strWhere As String
Dim strWhere1 As String
Dim strWhere2 As String
Dim strWhere3 As String


stDocName = "Report1"

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please make sure you entered a start and end date."
Exit Sub
Else

strWhere1 = [lstArea]
strWhere2 = [lstProduct]
strWhere3 = [cboReviewer]

If Len(strWhere1) > 0 Then
strWhere = strWhere & strWhere1 & " AND "
End If

If Len(strWhere2) > 0 Then
strWhere = strWhere & strWhere2 & " AND "
End If

If Len(strWhere3) > 0 Then
strWhere = strWhere & strWhere3 & " AND "
End If

If Len(strWhere) > 0 Then
strWhere = " WHERE " & Left$(strWhere, Len(strWhere - 5))
End If

//////////////////////////////////


:

You've declared strWhere as an Integer, but you're trying to assign a
String
to it.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I've simplified the code to only pull in one value if entered.
The only error I get is a popup saying "13 Type Mismatch"
Any idea what that means???
Or at what point in my code to correct??

Private Sub cmdKey_Click()
On Error GoTo Err_cmdKey_Click
Dim stDocName As String
Dim strWhere As Integer
Dim strWhere3 As Integer

stDocName = "rptQualityAuditList"
strReport = "Audit"

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please enter a start and end date to run this
report."
Exit Sub
Else

strWhere3 = [cboReviewer]

If Len(strWhere3) > 0 Then
strWhere = strWhere & strWhere3 & " AND "
End If


stStart = Me.txtStart
stEnd = Me.txtEnd

'DoCmd.SendObject acReport, stDocName, acFormatRTF, , , , , ,
True
DoCmd.OpenReport stDocName, acPreview
End If

:

Your code below answers a lot of questions and makes what I've been
trying to
accomplish it look simple.
But your last "If" confuses me, I don't see how all 3 values are
passed
to
"strWhere" or what it does?
My 3 values are "lstArea","lstProduct" and "cboReviewer"

So here is what a I did. It bombs at the end: Len(strWhere - 5 :

Dim strWhere As Integer
Dim strWhere1 As Integer
Dim strWhere2 As Integer
Dim strWhere3 As Integer


stDocName = "rptQualityAuditList"
strReport = "Audit"

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please enter a start and end date to run this
report."
Exit Sub
Else

strWhere1 = [lstArea]
strWhere2 = [lstProduct]
strWhere3 = [cboReviewer]

If Len(strWhere1) > 0 Then
strWhere = strWhere & strWhere1 & " AND "
End If
If Len(strWhere2) > 0 Then
strWhere = strWhere & strWhere2 & " AND "
End If
If Len(strWhere3) > 0 Then
strWhere = strWhere & strWhere3 & " AND "
End If

If Len(strWhere) > 0 Then
strWhere = " WHERE " & Left$(strWhere, Len(strWhere - 5))
End If


Thanks







:

You've already got an Else in the construction: you can't use
ElseIf
once
you've used Else. Not only that, but ElseIf requires a condition
to
evaluate:

If condition Then
[statements]
[ElseIf condition-n Then
[elseifstatements] ...
[Else
[elsestatements]]
End If

What I typically do is take each part separately. For example,
I'll
define
variables strWhere1, strWhere2 and strWhere3, as well as an
overall
strWhere. I'll then have a section of code that possible defines
strWhere1,
or leaves it blank if there isn't anything applicable to that
condition.
Similarly, I'll either define strWhere2 and strWhere3, or leave
them
blank,
depending on the fields on the form.

Once I've done all that, I'll complete the Where clause by
checking
the
values of each of the variables:

If Len(strWhere1) > 0 Then
strWhere = strWhere & strWhere1 & " AND "
End If
If Len(strWhere2) > 0 Then
strWhere = strWhere & strWhere2 & " AND "
End If
If Len(strWhere3) > 0 Then
strWhere = strWhere & strWhere3 & " AND "
End If

If Len(strWhere) > 0 Then
strWhere = " WHERE " & Left$(strWhere, Len(strWhere - 5))
End If



--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I tried using "ElseIf" and just duplicate the X-value.
Could you look at this to see why it will not allow an "ElseIf"
(Note: These values are Public
Public stStart As String
Public stEnd As String
Public stAreaList As String
Public stRevList As String)


Dim stDocName As String
Dim X As Integer
Dim Y As Integer
Dim stArea As Variant
Dim stReviewer As Variant

stDocName = "rptQualityAuditList"
strReport = "Audit"

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please enter a start and end date to run this
report."
Exit Sub
Else
X = 0
For Each stArea In lstArea.ItemsSelected
If X = 0 Then
stAreaList = "In('" & lstArea.ItemData(stArea) &
"'"
Else
stAreaList = stAreaList & ",'" &
lstArea.ItemData(stArea) &
"'"
End If
X = X + 1
Next stArea

stAreaList = stAreaList & ")"

ElseIf

Y = 0
For Each stReviewer In cboReviewer.ItemsSelected
If Y = 0 Then
stRevList = "In('" &
cboReviewer.ItemData(stReviewer)
& "'"
Else
stRevList = stRevList & ",'" &
cboReviewer.ItemData(cboReviewer) & "'"
End If
Y = Y + 1
Next cboReviewer

stRevList = stRevList & ")"
End If


If stRevList = ")" Then
MsgBox "Please select a Location."

stStart = Me.txtStart
stEnd = Me.txtEnd

Else
 
D

Dan @BCBS

First, thanks for all the help..

I started over clean:
The below code has lines commented out, when I run it I get the date range
of data I need.
But when I remove the comment out hyphens the error pop up window says
"94-Invalid use of Null" and does not show me which line is bombing..
It's only reading in one String (strWhere1) once I get this one under
control, I'll add the other two.

Dim stDocName As String
Dim strWhere As String
Dim strWhere1 As String


stDocName = "Report1"

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please make sure you entered a start and end date."
Exit Sub
Else

'strWhere1 = [lstArea]

'If Len(strWhere1) > 0 Then
' strWhere = strWhere & strWhere1 & " AND "
' End If

' If Len(strWhere) > 0 Then
' strWhere = " WHERE " & Left$(strWhere, Len(strWhere) - 5)
'End If

stStart = Me.txtStart
stEnd = Me.txtEnd
DoCmd.OpenReport stDocName, acPreview
End If
/////////////////////

Dan @BCBS said:
Douglas J. Steele said:
On what line of code is that error occurring?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Dan @BCBS said:
I'm getting past (strWhere - 5) But I'm getting an " 94 Invalid Use Of
Null"
Even without the ""If IsNull(Me.txtStart) Or...""

??



:

There's a closing parenthesis in the wrong place:

strWhere = " WHERE " & Left$(strWhere, Len(strWhere) - 5)


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


That certainly was an over sight on my part.
But even so, I get the same error message at: (strWhere - 5))
Dim stDocName As String
Dim strWhere As String
Dim strWhere1 As String
Dim strWhere2 As String
Dim strWhere3 As String


stDocName = "Report1"

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please make sure you entered a start and end date."
Exit Sub
Else

strWhere1 = [lstArea]
strWhere2 = [lstProduct]
strWhere3 = [cboReviewer]

If Len(strWhere1) > 0 Then
strWhere = strWhere & strWhere1 & " AND "
End If

If Len(strWhere2) > 0 Then
strWhere = strWhere & strWhere2 & " AND "
End If

If Len(strWhere3) > 0 Then
strWhere = strWhere & strWhere3 & " AND "
End If

If Len(strWhere) > 0 Then
strWhere = " WHERE " & Left$(strWhere, Len(strWhere - 5))
End If

//////////////////////////////////


:

You've declared strWhere as an Integer, but you're trying to assign a
String
to it.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I've simplified the code to only pull in one value if entered.
The only error I get is a popup saying "13 Type Mismatch"
Any idea what that means???
Or at what point in my code to correct??

Private Sub cmdKey_Click()
On Error GoTo Err_cmdKey_Click
Dim stDocName As String
Dim strWhere As Integer
Dim strWhere3 As Integer

stDocName = "rptQualityAuditList"
strReport = "Audit"

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please enter a start and end date to run this
report."
Exit Sub
Else

strWhere3 = [cboReviewer]

If Len(strWhere3) > 0 Then
strWhere = strWhere & strWhere3 & " AND "
End If


stStart = Me.txtStart
stEnd = Me.txtEnd

'DoCmd.SendObject acReport, stDocName, acFormatRTF, , , , , ,
True
DoCmd.OpenReport stDocName, acPreview
End If

:

Your code below answers a lot of questions and makes what I've been
trying to
accomplish it look simple.
But your last "If" confuses me, I don't see how all 3 values are
passed
to
"strWhere" or what it does?
My 3 values are "lstArea","lstProduct" and "cboReviewer"

So here is what a I did. It bombs at the end: Len(strWhere - 5 :

Dim strWhere As Integer
Dim strWhere1 As Integer
Dim strWhere2 As Integer
Dim strWhere3 As Integer


stDocName = "rptQualityAuditList"
strReport = "Audit"

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please enter a start and end date to run this
report."
Exit Sub
Else

strWhere1 = [lstArea]
strWhere2 = [lstProduct]
strWhere3 = [cboReviewer]

If Len(strWhere1) > 0 Then
strWhere = strWhere & strWhere1 & " AND "
End If
If Len(strWhere2) > 0 Then
strWhere = strWhere & strWhere2 & " AND "
End If
If Len(strWhere3) > 0 Then
strWhere = strWhere & strWhere3 & " AND "
End If

If Len(strWhere) > 0 Then
strWhere = " WHERE " & Left$(strWhere, Len(strWhere - 5))
End If


Thanks







:

You've already got an Else in the construction: you can't use
ElseIf
once
you've used Else. Not only that, but ElseIf requires a condition
to
evaluate:

If condition Then
[statements]
[ElseIf condition-n Then
[elseifstatements] ...
[Else
[elsestatements]]
End If

What I typically do is take each part separately. For example,
I'll
define
variables strWhere1, strWhere2 and strWhere3, as well as an
overall
strWhere. I'll then have a section of code that possible defines
strWhere1,
or leaves it blank if there isn't anything applicable to that
condition.
Similarly, I'll either define strWhere2 and strWhere3, or leave
them
blank,
depending on the fields on the form.

Once I've done all that, I'll complete the Where clause by
checking
the
values of each of the variables:

If Len(strWhere1) > 0 Then
strWhere = strWhere & strWhere1 & " AND "
End If
If Len(strWhere2) > 0 Then
strWhere = strWhere & strWhere2 & " AND "
End If
If Len(strWhere3) > 0 Then
strWhere = strWhere & strWhere3 & " AND "
End If

If Len(strWhere) > 0 Then
strWhere = " WHERE " & Left$(strWhere, Len(strWhere - 5))
End If



--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


I tried using "ElseIf" and just duplicate the X-value.
Could you look at this to see why it will not allow an "ElseIf"
(Note: These values are Public
Public stStart As String
Public stEnd As String
Public stAreaList As String
Public stRevList As String)


Dim stDocName As String
Dim X As Integer
Dim Y As Integer
Dim stArea As Variant
Dim stReviewer As Variant

stDocName = "rptQualityAuditList"
strReport = "Audit"

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please enter a start and end date to run this
report."
Exit Sub
Else
X = 0
For Each stArea In lstArea.ItemsSelected
If X = 0 Then
stAreaList = "In('" & lstArea.ItemData(stArea) &
"'"
Else
stAreaList = stAreaList & ",'" &
lstArea.ItemData(stArea) &
"'"
End If
X = X + 1
Next stArea

stAreaList = stAreaList & ")"

ElseIf

Y = 0
For Each stReviewer In cboReviewer.ItemsSelected
If Y = 0 Then
stRevList = "In('" &
cboReviewer.ItemData(stReviewer)
& "'"
Else
stRevList = stRevList & ",'" &
cboReviewer.ItemData(cboReviewer) & "'"
End If
Y = Y + 1
Next cboReviewer

stRevList = stRevList & ")"
End If


If stRevList = ")" Then
MsgBox "Please select a Location."

stStart = Me.txtStart
 
D

Douglas J. Steele

What is lstArea? From the name, I'd assume it's a list box. Does it have
anything selected? If not, that's a problem: an empty list box returns Null,
and you can't assign Null to a String variable. If it does have something
selected, is it set to allow multiselect? If so, that's a problem:
multiselect list boxes always return Null, regardless of whether or not
something's selected in them.

For the first case, you'll need:

If IsNull(Me.lstArea) = False Then
strWhere1 = [lstArea]
strWhere = strWhere & strWhere1 & " AND "
End If

(there's no need to check whether Len(strWhere1) > 0, since if it's not
null, it has a value)

For the second case, you'll need to use code like what's in
http://www.mvps.org/access/forms/frm0007.htm at "The Access Web"

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Dan @BCBS said:
First, thanks for all the help..

I started over clean:
The below code has lines commented out, when I run it I get the date range
of data I need.
But when I remove the comment out hyphens the error pop up window says
"94-Invalid use of Null" and does not show me which line is bombing..
It's only reading in one String (strWhere1) once I get this one under
control, I'll add the other two.

Dim stDocName As String
Dim strWhere As String
Dim strWhere1 As String


stDocName = "Report1"

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please make sure you entered a start and end date."
Exit Sub
Else

'strWhere1 = [lstArea]

'If Len(strWhere1) > 0 Then
' strWhere = strWhere & strWhere1 & " AND "
' End If

' If Len(strWhere) > 0 Then
' strWhere = " WHERE " & Left$(strWhere, Len(strWhere) - 5)
'End If

stStart = Me.txtStart
stEnd = Me.txtEnd
DoCmd.OpenReport stDocName, acPreview
End If
/////////////////////

Dan @BCBS said:
Douglas J. Steele said:
On what line of code is that error occurring?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I'm getting past (strWhere - 5) But I'm getting an " 94 Invalid Use
Of
Null"
Even without the ""If IsNull(Me.txtStart) Or...""

??



:

There's a closing parenthesis in the wrong place:

strWhere = " WHERE " & Left$(strWhere, Len(strWhere) - 5)


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


That certainly was an over sight on my part.
But even so, I get the same error message at: (strWhere - 5))
Dim stDocName As String
Dim strWhere As String
Dim strWhere1 As String
Dim strWhere2 As String
Dim strWhere3 As String


stDocName = "Report1"

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please make sure you entered a start and end date."
Exit Sub
Else

strWhere1 = [lstArea]
strWhere2 = [lstProduct]
strWhere3 = [cboReviewer]

If Len(strWhere1) > 0 Then
strWhere = strWhere & strWhere1 & " AND "
End If

If Len(strWhere2) > 0 Then
strWhere = strWhere & strWhere2 & " AND "
End If

If Len(strWhere3) > 0 Then
strWhere = strWhere & strWhere3 & " AND "
End If

If Len(strWhere) > 0 Then
strWhere = " WHERE " & Left$(strWhere, Len(strWhere - 5))
End If

//////////////////////////////////


:

You've declared strWhere as an Integer, but you're trying to
assign a
String
to it.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I've simplified the code to only pull in one value if entered.
The only error I get is a popup saying "13 Type Mismatch"
Any idea what that means???
Or at what point in my code to correct??

Private Sub cmdKey_Click()
On Error GoTo Err_cmdKey_Click
Dim stDocName As String
Dim strWhere As Integer
Dim strWhere3 As Integer

stDocName = "rptQualityAuditList"
strReport = "Audit"

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please enter a start and end date to run this
report."
Exit Sub
Else

strWhere3 = [cboReviewer]

If Len(strWhere3) > 0 Then
strWhere = strWhere & strWhere3 & " AND "
End If


stStart = Me.txtStart
stEnd = Me.txtEnd

'DoCmd.SendObject acReport, stDocName, acFormatRTF, , , ,
, ,
True
DoCmd.OpenReport stDocName, acPreview
End If

:

Your code below answers a lot of questions and makes what I've
been
trying to
accomplish it look simple.
But your last "If" confuses me, I don't see how all 3 values
are
passed
to
"strWhere" or what it does?
My 3 values are "lstArea","lstProduct" and "cboReviewer"

So here is what a I did. It bombs at the end: Len(strWhere -
5 :

Dim strWhere As Integer
Dim strWhere1 As Integer
Dim strWhere2 As Integer
Dim strWhere3 As Integer


stDocName = "rptQualityAuditList"
strReport = "Audit"

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please enter a start and end date to run this
report."
Exit Sub
Else

strWhere1 = [lstArea]
strWhere2 = [lstProduct]
strWhere3 = [cboReviewer]

If Len(strWhere1) > 0 Then
strWhere = strWhere & strWhere1 & " AND "
End If
If Len(strWhere2) > 0 Then
strWhere = strWhere & strWhere2 & " AND "
End If
If Len(strWhere3) > 0 Then
strWhere = strWhere & strWhere3 & " AND "
End If

If Len(strWhere) > 0 Then
strWhere = " WHERE " & Left$(strWhere, Len(strWhere - 5))
End If


Thanks







:

You've already got an Else in the construction: you can't
use
ElseIf
once
you've used Else. Not only that, but ElseIf requires a
condition
to
evaluate:

If condition Then
[statements]
[ElseIf condition-n Then
[elseifstatements] ...
[Else
[elsestatements]]
End If

What I typically do is take each part separately. For
example,
I'll
define
variables strWhere1, strWhere2 and strWhere3, as well as an
overall
strWhere. I'll then have a section of code that possible
defines
strWhere1,
or leaves it blank if there isn't anything applicable to
that
condition.
Similarly, I'll either define strWhere2 and strWhere3, or
leave
them
blank,
depending on the fields on the form.

Once I've done all that, I'll complete the Where clause by
checking
the
values of each of the variables:

If Len(strWhere1) > 0 Then
strWhere = strWhere & strWhere1 & " AND "
End If
If Len(strWhere2) > 0 Then
strWhere = strWhere & strWhere2 & " AND "
End If
If Len(strWhere3) > 0 Then
strWhere = strWhere & strWhere3 & " AND "
End If

If Len(strWhere) > 0 Then
strWhere = " WHERE " & Left$(strWhere, Len(strWhere - 5))
End If



--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


message
I tried using "ElseIf" and just duplicate the X-value.
Could you look at this to see why it will not allow an
"ElseIf"
(Note: These values are Public
Public stStart As String
Public stEnd As String
Public stAreaList As String
Public stRevList As String)


Dim stDocName As String
Dim X As Integer
Dim Y As Integer
Dim stArea As Variant
Dim stReviewer As Variant

stDocName = "rptQualityAuditList"
strReport = "Audit"

If IsNull(Me.txtStart) Or IsNull(Me.txtEnd) Then
MsgBox "Please enter a start and end date to run
this
report."
Exit Sub
Else
X = 0
For Each stArea In lstArea.ItemsSelected
If X = 0 Then
stAreaList = "In('" &
lstArea.ItemData(stArea) &
"'"
Else
stAreaList = stAreaList & ",'" &
lstArea.ItemData(stArea) &
"'"
End If
X = X + 1
Next stArea

stAreaList = stAreaList & ")"

ElseIf

Y = 0
For Each stReviewer In cboReviewer.ItemsSelected
If Y = 0 Then
stRevList = "In('" &
cboReviewer.ItemData(stReviewer)
& "'"
Else
stRevList = stRevList & ",'" &
cboReviewer.ItemData(cboReviewer) & "'"
End If
Y = Y + 1
Next cboReviewer

stRevList = stRevList & ")"
End If


If stRevList = ")" Then
MsgBox "Please select a Location."

stStart = Me.txtStart
 

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

Combo Box 15
3 choices 3
3 list boxes 1 answer 9
DoCmd.OpenQuery 4
DoCmd.SendObject 2
Type Mismatch 5
Match style 0
Making a macro only work on certain files 2

Top