I'm sure the concept is valid. I'm trying to pass the results of multiple combo boxes to a SQL string to be used in a query. Here's what I have so far. The message I get is "can't find the object 'stDocName'"
There may be issues beyond this. But I haven't gotten past this error.
Private Sub cmdSubmit_Click()
On Error GoTo Err_cmdSubmit_Click
Dim strWhere As String 'String variable to store where clause
If Len(Me.cboIncome & "" > 0 Then
strWhere = strWhere & " AND INCOME = '" & Me.cboIncome & "'"
End If
If Len(Me.cboGender & "" > 0 Then
strWhere = strWhere & " AND GENDER = '" & Me.cboGender & "'"
End If
If Len(Me.cboMaritalStatus & "" > 0 Then
strWhere = strWhere & " AND MARITAL_STATUS = '" & Me.cboMaritalStatus & "'"
End If
If Len(Me.cboOwnRent & "" > 0 Then
strWhere = strWhere & " AND OWNRENT = '" & Me.cboOwnRent & "'"
End If
If Len(Me.cboEducation & "" > 0 Then
strWhere = strWhere & " AND EDUCATION = '" & Me.cboEducation & "'"
End If
'If Len(Me.cboMembers & "" > 0 Then
' strWhere = strWhere & " AND MEMBERS_IN_HOUSEHOLD = '" & Me.cboMembers & "'"
'End If
If Len(Me.dtmBeginDate & "" > 0 And Len(Me.dtmEndDate & "" > 0 Then
' entries in both
strWhere = strWhere & " AND DATE_OF_BIRTH Between #" & Me.dtmBeginDate & "# AND #" & Me.dtmEndDate & "#"
End If
If Len(Me.dtmBeginDate & "" > 0 And Len(Me.dtmEndDate & "" = 0 Then
' user put something in From date only
MsgBox "You did not enter Both Dates.", vbInformation
GoTo Exit_cmdSubmit_Click:
End If
If Len(Me.dtmBeginDate & "" = 0 And Len(Me.dtmEndDate & "" > 0 Then
' user put something in to date only
MsgBox "You did not enter Both Dates.", vbInformation
GoTo Exit_cmdSubmit_Click:
End If ' no need to specify anything if nothing selected
'Open the form
If Len(strWhere & "" = 0 Then
' no options selected.
MsgBox "No Items have been selected," & (Chr(13)) & (Chr(13)) & _
"Please Select Demographic Criteria", vbExclamation, _
"No Data Error"
GoTo Exit_cmdSubmit_Click:
Else
Dim strSQL As String
Dim stDocName As String
strSQL = "SELECT dbo_INDIVIDUAL.INDIVIDUAL_ID, dbo_INDIVIDUAL.ADDRESS1, dbo_INDIVIDUAL.ADDRESS2, dbo_INDIVIDUAL.CITY, dbo_INDIVIDUAL.STATE, dbo_INDIVIDUAL.ZIP5, dbo_INDIVIDUAL.ZIP4, dbo_DEMOGRAPHIC.DATE_OF_BIRTH, dbo_DEMOGRAPHIC.INCOME, dbo_DEMOGRAPHIC.OWNRENT, dbo_DEMOGRAPHIC.GENDER, dbo_DEMOGRAPHIC.REMINGTON_PRODUCTS_OWNED, dbo_DEMOGRAPHIC.EDUCATION, dbo_DEMOGRAPHIC.MARITAL_STATUS, dbo_DEMOGRAPHIC.MEMBERS_IN_HOUSEHOLD" & _
"FROM dbo_INDIVIDUAL INNER JOIN dbo_DEMOGRAPHIC ON dbo_INDIVIDUAL.INDIVIDUAL_ID = dbo_DEMOGRAPHIC.INDIVIDUAL_ID" & _
"WHERE (Mid(strWhere, 6)"
stDocName = "strSQL"
DoCmd.OpenQuery "strDocName", acViewNormal
DoCmd.OpenForm "frmDemographicResults", acFormDS
DoCmd.Maximize
End If
Exit_cmdSubmit_Click:
Exit Sub
Err_cmdSubmit_Click:
MsgBox Err.Description
Resume Exit_cmdSubmit_Click
End Sub
Any help here would be appreciated.
TIA,
Melanie
There may be issues beyond this. But I haven't gotten past this error.
Private Sub cmdSubmit_Click()
On Error GoTo Err_cmdSubmit_Click
Dim strWhere As String 'String variable to store where clause
If Len(Me.cboIncome & "" > 0 Then
strWhere = strWhere & " AND INCOME = '" & Me.cboIncome & "'"
End If
If Len(Me.cboGender & "" > 0 Then
strWhere = strWhere & " AND GENDER = '" & Me.cboGender & "'"
End If
If Len(Me.cboMaritalStatus & "" > 0 Then
strWhere = strWhere & " AND MARITAL_STATUS = '" & Me.cboMaritalStatus & "'"
End If
If Len(Me.cboOwnRent & "" > 0 Then
strWhere = strWhere & " AND OWNRENT = '" & Me.cboOwnRent & "'"
End If
If Len(Me.cboEducation & "" > 0 Then
strWhere = strWhere & " AND EDUCATION = '" & Me.cboEducation & "'"
End If
'If Len(Me.cboMembers & "" > 0 Then
' strWhere = strWhere & " AND MEMBERS_IN_HOUSEHOLD = '" & Me.cboMembers & "'"
'End If
If Len(Me.dtmBeginDate & "" > 0 And Len(Me.dtmEndDate & "" > 0 Then
' entries in both
strWhere = strWhere & " AND DATE_OF_BIRTH Between #" & Me.dtmBeginDate & "# AND #" & Me.dtmEndDate & "#"
End If
If Len(Me.dtmBeginDate & "" > 0 And Len(Me.dtmEndDate & "" = 0 Then
' user put something in From date only
MsgBox "You did not enter Both Dates.", vbInformation
GoTo Exit_cmdSubmit_Click:
End If
If Len(Me.dtmBeginDate & "" = 0 And Len(Me.dtmEndDate & "" > 0 Then
' user put something in to date only
MsgBox "You did not enter Both Dates.", vbInformation
GoTo Exit_cmdSubmit_Click:
End If ' no need to specify anything if nothing selected
'Open the form
If Len(strWhere & "" = 0 Then
' no options selected.
MsgBox "No Items have been selected," & (Chr(13)) & (Chr(13)) & _
"Please Select Demographic Criteria", vbExclamation, _
"No Data Error"
GoTo Exit_cmdSubmit_Click:
Else
Dim strSQL As String
Dim stDocName As String
strSQL = "SELECT dbo_INDIVIDUAL.INDIVIDUAL_ID, dbo_INDIVIDUAL.ADDRESS1, dbo_INDIVIDUAL.ADDRESS2, dbo_INDIVIDUAL.CITY, dbo_INDIVIDUAL.STATE, dbo_INDIVIDUAL.ZIP5, dbo_INDIVIDUAL.ZIP4, dbo_DEMOGRAPHIC.DATE_OF_BIRTH, dbo_DEMOGRAPHIC.INCOME, dbo_DEMOGRAPHIC.OWNRENT, dbo_DEMOGRAPHIC.GENDER, dbo_DEMOGRAPHIC.REMINGTON_PRODUCTS_OWNED, dbo_DEMOGRAPHIC.EDUCATION, dbo_DEMOGRAPHIC.MARITAL_STATUS, dbo_DEMOGRAPHIC.MEMBERS_IN_HOUSEHOLD" & _
"FROM dbo_INDIVIDUAL INNER JOIN dbo_DEMOGRAPHIC ON dbo_INDIVIDUAL.INDIVIDUAL_ID = dbo_DEMOGRAPHIC.INDIVIDUAL_ID" & _
"WHERE (Mid(strWhere, 6)"
stDocName = "strSQL"
DoCmd.OpenQuery "strDocName", acViewNormal
DoCmd.OpenForm "frmDemographicResults", acFormDS
DoCmd.Maximize
End If
Exit_cmdSubmit_Click:
Exit Sub
Err_cmdSubmit_Click:
MsgBox Err.Description
Resume Exit_cmdSubmit_Click
End Sub
Any help here would be appreciated.
TIA,
Melanie