Hi there
I am in need of some help with an SQL VBA string
I have created a search form and I am now trying to make a search feature using dates.
I have 2 textboxes txtSearch1 & txtSearch2
what I am trying to do is use both the text boxes togeather to achieve my result.
I would like if only txtSearch1 contained information for the sql statement to only use the criteria in that box but if there was another criteria in txtSearch2 then for both the txtboxes to work togeather.
e.g
if txtSearch1 had the date 01/08/05 then the search would only contain that date but if
txtSearch1 had the date 01/05/05 & txtSearch2 had the date 01/08/05 then the search would find everything in between.
This is what I am trying to work on at the moment.......Please don't laugh to much
As you see help would be of great help!!!
TIA
I am in need of some help with an SQL VBA string
I have created a search form and I am now trying to make a search feature using dates.
I have 2 textboxes txtSearch1 & txtSearch2
what I am trying to do is use both the text boxes togeather to achieve my result.
I would like if only txtSearch1 contained information for the sql statement to only use the criteria in that box but if there was another criteria in txtSearch2 then for both the txtboxes to work togeather.
e.g
if txtSearch1 had the date 01/08/05 then the search would only contain that date but if
txtSearch1 had the date 01/05/05 & txtSearch2 had the date 01/08/05 then the search would find everything in between.
This is what I am trying to work on at the moment.......Please don't laugh to much
Code:
Private Sub SearchStartDate()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
Dim strFilterSQL As String
Dim txtSearch1 As String
Dim txtSearch2 As String
txtSearch1 = Me.txtSearch1.Value
txtSearch2 = Me.txtSearch2.Value
Set db = CurrentDb
Set qdf = db.QueryDefs("qrySearch")
If txtSearch2.Value Is Null Then txtSearch2 = txtSearch1
strSQL = "SELECT tblMain.[bkg no],tblMain.[Surname],tblMain.[TempName],tblMain.[Department],tblMain.[Taken By],tblMain.[Reporting To],tblMain.[Start Date],tblMain.[End Date] " & _
"FROM tblMain " & _
"WHERE tblMain.[Start Date] Between [Forms]![frmSearch]![txtSearch1] And [Forms]![frmSearch]![txtSearch2]" & _
"ORDER BY tblMain.[Start Date]"
qdf.SQL = strSQL
Me.lstSearchResults.RowSource = "qrysearch"
Set qdf = Nothing
Set db = Nothing
End Sub
As you see help would be of great help!!!
TIA