how to add another strwhere criteria
hi
all
I have some code that exports data to excel overwrites old data on the same sheet every time call "exspose Data" but I now need to add another string to only export current year data
how it works it creates a temp query then exports to excel and it then delete's it
my vba knowledge is very little
here's my code it works but don't filter Dateyear to current year show all years
bold in red Text is the new lines I have added
and some how I need to add this as my where str
I think
unsure how to add it
thanks in advance
shane
hi
all
I have some code that exports data to excel overwrites old data on the same sheet every time call "exspose Data" but I now need to add another string to only export current year data
how it works it creates a temp query then exports to excel and it then delete's it
my vba knowledge is very little
here's my code it works but don't filter Dateyear to current year show all years
bold in red Text is the new lines I have added
Code:
Dim dbs As DAO.Database
Dim qryDef As DAO.QueryDef
Dim strWhere As String
Dim lngLen As Long
Set dbs = CurrentDb
Dim strSQL As String
strSQL = "SELECT tblemployee.Id, tblExposure.Dateexposure, [Valuef/cm]*[Durationofexposure] AS [Total Ex], tblemployee.firstname, tblemployee.lastname, [COLOR=red][B]Year([Dateexposure]) AS DateYear[/B][/COLOR] " & _
" FROM tblExposure " & _
" INNER JOIN tblemployee ON tblExposure.ID = tblemployee.ID "
If [Forms]![Frmemployee]![CboMoveTo] <> "" Then
strWhere = strWhere & "([tblemployee.ID] = " & [Forms]![Frmemployee]![CboMoveTo] & ") AND "
End If
lngLen = Len(strWhere) - 5
DoCmd.Hourglass True
If lngLen <= 0 Then
strSQL = strSQL
Set qryDef = dbs.CreateQueryDef("Exposure Data", strSQL)
qryDef.Close
Set qryDef = Nothing
DoEvents
SaveQueriesToExcel "C:\Users\Dell\Documents\excel test.xlsm", "Exposure Data"
DoEvents
DoCmd.DeleteObject acQuery, "Exposure Data"
Else
strWhere = Left$(strWhere, lngLen)
strSQL = strSQL & " WHERE " & strWhere
Set qryDef = dbs.CreateQueryDef("Exposure Data", strSQL)
qryDef.Close
Set qryDef = Nothing
DoEvents
SaveQueriesToExcel "C:\Users\Dell\Documents\excel test.xlsm", "Exposure Data"
DoEvents
DoCmd.DeleteObject acQuery, "Exposure Data"
End If
DoCmd.Hourglass False
DoCmd.CancelEvent
Code:
((Year([Dateexposure]))=Year(Now())));"
thanks in advance
shane
Last edited: