So trying to fix one error, I have discovered/created another. I was advised to start a new thread and attach the full code I'm 'working with' ('ineffectually clubbing at' might be a better term to describe where I'm at right now!).
My goal with this code is to allow me to search my simple database (two tables linked by an autonumbered ID column). I have adapted code from the internet, using help from here and my very rudimentary VBA knowledge (mostly from Excel macros and logic, rather than Access know how).
Here's the VBA bits:
And here's the query:
Any help would be greatly appreciated! :)
[z{Link to backstory: http://bytes.com/topic/access/answer...ismatch-errors]
My goal with this code is to allow me to search my simple database (two tables linked by an autonumbered ID column). I have adapted code from the internet, using help from here and my very rudimentary VBA knowledge (mostly from Excel macros and logic, rather than Access know how).
Here's the VBA bits:
Code:
Option Compare Database
Option Explicit
Private Sub btnClear_Click()
Dim intIndex As Integer
' Clear all search items
Me.txtConcessionNo = ""
Me.txtCategory = ""
Me.txtProject = ""
Me.txtDateCreated = ""
Me.txtPartNo = ""
Me.txtDescription = ""
Me.txtDocumentNo = ""
Me.txtReferenceNo = ""
btnSearch_Click
End Sub
Private Sub btnSearch_Click()
Dim sqlinput As Variant
' Update the record source
sqlinput = "SELECT * FROM FileInfQry " & BuildFilter
Debug.Print sqlinput
Me.FileInfSubForm.Form.RecordSource = sqlinput
' Requery the subform
Me.FileInfSubForm.Requery
End Sub
Private Sub Form_Load()
' Clear the search form
btnClear_Click
End Sub
Private Function BuildFilter() As Variant
Dim varWhere As Variant
Dim varItem As Variant
Dim intIndex As Integer
varWhere = Null ' Main filter
' Check for Concession Number
If Me.txtConcessionNo > "" Then
varWhere = varWhere & "[ConcessionNo] LIKE """ & Me.txtConcessionNo & "*"" And "
End If
' Check for Category
If Me.txtCategory > "" Then
varWhere = varWhere & "[Category] LIKE """ & Me.txtCategory & "*"" And "
End If
' Check for Project
If Me.txtProject > "" Then
varWhere = varWhere & "[Project] LIKE """ & Me.txtProject & "*"" And "
End If
' Check for Date Created
If Me.txtDateCreated > "" Then
varWhere = varWhere & "[DateCreated] #" & Format(Me.txtDateCreated, "DD/MM/YYYY") & "# AND "
End If
' Check for Part Number
If Me.txtPartNo > "" Then
varWhere = varWhere & "[PartNo] LIKE """ & Me.txtPartNo & "*"" AND "
End If
' Check for Description
If Me.txtDescription > "" Then
varWhere = varWhere & "[Description] LIKE """ & Me.txtDescription & "*"" AND "
End If
' Check for Document Number
If Me.txtDocumentNo > "" Then
varWhere = varWhere & "[DocumentNo] LIKE """ & Me.txtDocumentNo & "*"" AND "
End If
' Check for Reference Number
If Me.txtReferenceNo > "" Then
varWhere = varWhere & "[ReferenceNo] LIKE """ & Me.txtReferenceNo & "*"" AND "
End If
' Check if there is a filter to return...
If IsNull(varWhere) Then
varWhere = ""
Else
varWhere = "WHERE " & varWhere
' strip off last "AND" in the filter
If Right(varWhere, 5) = " AND " Then
varWhere = Left(varWhere, Len(varWhere) - 5)
End If
End If
BuildFilter = varWhere
End Function
Code:
SELECT FileInformation.ConcessionNo AS ConcessionNo
, FileInformation.Category AS Category
, FileInformation.Project AS Project
, FileInformation.DateCreated AS DateCreated
, FileInformation.PartNo AS PartNo
, FileInformation.Description AS Description
, FileInformation.DocumentNo AS DocumentNo
, FileInformation.ReferenceNo AS ReferenceNo
, Files.LinkPath AS Path
FROM FileInformation, Files
WHERE (((FileInformation.ID)=[Files].[FileID]));
[z{Link to backstory: http://bytes.com/topic/access/answer...ismatch-errors]
Comment