S
SteelFire via AccessMonster.com
I am trying to get my query to run off of VBA. As of now, I could not get it
to work so have made an SQL to run it. The SQL is at the bottom. The VBA that
I was running keeps bringing up the error 3011 that reads "The MS Office
Access database engine could not find the object" if strWhere is set as the
[FilterName] and error 3126 that reads "Invalid bracketing of the name" if it
is set as the [WhereCondition]. How would I go about making the changes
needed to make the VBA work for the query. The VBA reads:
=========================================================================
VBA-----
=========================================================================
Private Sub cmdOK_Click()
Dim strWhere As String 'The criteria string.
Dim lngLen As Long 'Length of the criteria string to
append to.
Const conJetDate = "\#mm\/dd\/yyyy\#" 'The format expected for dates in
a JET query string.
On Error GoTo Err_Handler
'Start of Body of Procedure***********************************
If Not IsNull(Me.cboCategory) Then
strWhere = strWhere & "([tblPartList.CategoryName] = """ & Me.
cboCategory & """) AND "
End If
If Not IsNull(Me.cboType) Then
strWhere = strWhere & "([CategoryType] = """ & Me.cboType & """) AND
"
End If
If Not IsNull(Me.txtSDate) Then
strWhere = strWhere & "([RevDate] >= " & Format(Me.txtSDate,
conJetDate) & ") AND "
End If
If Not IsNull(Me.txtEDate) Then
strWhere = strWhere & "([RevDate] < " & Format(Me.txtEDate + 1,
conJetDate) & ") AND "
End If
If Not IsNull(Me.cboDrawn) Then
strWhere = strWhere & "([DrawnBy] = """ & Me.cboDrawn & """) AND "
End If
If Not IsNull(Me.cboPart) Then
strWhere = strWhere & "([PartNum] = """ & Me.cboPart & """) AND "
End If
If Not IsNull(Me.cboJob) Then
strWhere = strWhere & "([JobNum] = """ & Me.cboJob & """) AND "
End If
If Not IsNull(Me.cboLocation) Then
DoCmd.OpenQuery "qryCustomers"
strWhere = strWhere & "([CustomerID] = SELECT DISTINCT qryCustomers.
CustomerID FROM qryCustomers ORDER BY qryCustomers.CustomerID) AND "
DoCmd.Close acQuery, "qryCustomers"
End If
If Not IsNull(Me.txtDesc) Then
strWhere = strWhere & "([PartDescription] = ""*" & Me.txtDesc & "*"")
AND "
End If
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
MsgBox "No criteria", vbInformation, "Nothing to do."
Else
strWhere = Left$(strWhere, lngLen)
DoCmd.Minimize
DoCmd.OpenForm "frmPartList", acNormal, , , strWhere
strWhere = ""
End If
'End of Body of Procedure***********************************
Exit_Handler:
Exit Sub
Err_Handler:
Call LogError(Err.Number, Err.Description, "cmdOK_Click from
Form_frmPartFinder")
Resume Exit_Handler
End Sub
=========================================================================
SQL-----
=========================================================================
SELECT tblPartTable.ID, tblPartTable.ProjectName, tblPartTable.
PartDescription, tblPartTable.PartNum, tblPartTable.JobNum, tblPartTable.
CategoryName, tblPartTable.CategoryType, tblPartTable.Rev, tblPartTable.
RevDate, tblPartTable.CustomerID, tblPartTable.FilePath, tblPartTable.
PartDrawingAtt, tblPartTable.Notes
FROM tblPartTable
WHERE (tblPartTable.CategoryName =[Forms]![frmPartFinder]![cboCategory] OR
[Forms]![frmPartFinder]![cboCategory] Is Null)
AND (tblPartTable.CategoryType =[Forms]![frmPartFinder]![cboType] OR [Forms]!
[frmPartFinder]![cboType] Is Null)
AND (tblPartTable.RevDate >=[Forms]![frmPartFinder]![txtSDate] OR [Forms]!
[frmPartFinder]![txtSDate] Is Null)
AND (tblPartTable.RevDate <[Forms]![frmPartFinder]![txtEDate] OR [Forms]!
[frmPartFinder]![txtEDate] Is Null)
AND (tblPartTable.DrawnBy=[Forms]![frmPartFinder]![cboDrawn] OR [Forms]!
[frmPartFinder]![cboDrawn] Is Null)
AND (tblPartTable.PartNum=[Forms]![frmPartFinder]![cboPart] OR [Forms]!
[frmPartFinder]![cboPart] Is Null)
AND (tblPartTable.JobNum =[Forms]![frmPartFinder]![cboJob] OR [Forms]!
[frmPartFinder]![cboJob] Is Null)
AND (tblPartTable.CustomerID = [Forms]![frmPartFinder]![cboCID] OR [Forms]!
[frmPartFinder]![cboCID] Is Null)
AND (tblPartTable.PartDescription Like "*" &[Forms]![frmPartFinder]![txtDesc]
& "*" OR [Forms]![frmPartFinder]![txtDesc] Is Null);
=========================================================================
to work so have made an SQL to run it. The SQL is at the bottom. The VBA that
I was running keeps bringing up the error 3011 that reads "The MS Office
Access database engine could not find the object" if strWhere is set as the
[FilterName] and error 3126 that reads "Invalid bracketing of the name" if it
is set as the [WhereCondition]. How would I go about making the changes
needed to make the VBA work for the query. The VBA reads:
=========================================================================
VBA-----
=========================================================================
Private Sub cmdOK_Click()
Dim strWhere As String 'The criteria string.
Dim lngLen As Long 'Length of the criteria string to
append to.
Const conJetDate = "\#mm\/dd\/yyyy\#" 'The format expected for dates in
a JET query string.
On Error GoTo Err_Handler
'Start of Body of Procedure***********************************
If Not IsNull(Me.cboCategory) Then
strWhere = strWhere & "([tblPartList.CategoryName] = """ & Me.
cboCategory & """) AND "
End If
If Not IsNull(Me.cboType) Then
strWhere = strWhere & "([CategoryType] = """ & Me.cboType & """) AND
"
End If
If Not IsNull(Me.txtSDate) Then
strWhere = strWhere & "([RevDate] >= " & Format(Me.txtSDate,
conJetDate) & ") AND "
End If
If Not IsNull(Me.txtEDate) Then
strWhere = strWhere & "([RevDate] < " & Format(Me.txtEDate + 1,
conJetDate) & ") AND "
End If
If Not IsNull(Me.cboDrawn) Then
strWhere = strWhere & "([DrawnBy] = """ & Me.cboDrawn & """) AND "
End If
If Not IsNull(Me.cboPart) Then
strWhere = strWhere & "([PartNum] = """ & Me.cboPart & """) AND "
End If
If Not IsNull(Me.cboJob) Then
strWhere = strWhere & "([JobNum] = """ & Me.cboJob & """) AND "
End If
If Not IsNull(Me.cboLocation) Then
DoCmd.OpenQuery "qryCustomers"
strWhere = strWhere & "([CustomerID] = SELECT DISTINCT qryCustomers.
CustomerID FROM qryCustomers ORDER BY qryCustomers.CustomerID) AND "
DoCmd.Close acQuery, "qryCustomers"
End If
If Not IsNull(Me.txtDesc) Then
strWhere = strWhere & "([PartDescription] = ""*" & Me.txtDesc & "*"")
AND "
End If
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
MsgBox "No criteria", vbInformation, "Nothing to do."
Else
strWhere = Left$(strWhere, lngLen)
DoCmd.Minimize
DoCmd.OpenForm "frmPartList", acNormal, , , strWhere
strWhere = ""
End If
'End of Body of Procedure***********************************
Exit_Handler:
Exit Sub
Err_Handler:
Call LogError(Err.Number, Err.Description, "cmdOK_Click from
Form_frmPartFinder")
Resume Exit_Handler
End Sub
=========================================================================
SQL-----
=========================================================================
SELECT tblPartTable.ID, tblPartTable.ProjectName, tblPartTable.
PartDescription, tblPartTable.PartNum, tblPartTable.JobNum, tblPartTable.
CategoryName, tblPartTable.CategoryType, tblPartTable.Rev, tblPartTable.
RevDate, tblPartTable.CustomerID, tblPartTable.FilePath, tblPartTable.
PartDrawingAtt, tblPartTable.Notes
FROM tblPartTable
WHERE (tblPartTable.CategoryName =[Forms]![frmPartFinder]![cboCategory] OR
[Forms]![frmPartFinder]![cboCategory] Is Null)
AND (tblPartTable.CategoryType =[Forms]![frmPartFinder]![cboType] OR [Forms]!
[frmPartFinder]![cboType] Is Null)
AND (tblPartTable.RevDate >=[Forms]![frmPartFinder]![txtSDate] OR [Forms]!
[frmPartFinder]![txtSDate] Is Null)
AND (tblPartTable.RevDate <[Forms]![frmPartFinder]![txtEDate] OR [Forms]!
[frmPartFinder]![txtEDate] Is Null)
AND (tblPartTable.DrawnBy=[Forms]![frmPartFinder]![cboDrawn] OR [Forms]!
[frmPartFinder]![cboDrawn] Is Null)
AND (tblPartTable.PartNum=[Forms]![frmPartFinder]![cboPart] OR [Forms]!
[frmPartFinder]![cboPart] Is Null)
AND (tblPartTable.JobNum =[Forms]![frmPartFinder]![cboJob] OR [Forms]!
[frmPartFinder]![cboJob] Is Null)
AND (tblPartTable.CustomerID = [Forms]![frmPartFinder]![cboCID] OR [Forms]!
[frmPartFinder]![cboCID] Is Null)
AND (tblPartTable.PartDescription Like "*" &[Forms]![frmPartFinder]![txtDesc]
& "*" OR [Forms]![frmPartFinder]![txtDesc] Is Null);
=========================================================================