Alright, I'm really new to SQL and VBA and all this, so I might be
completely off course...but just tell me. I know C and Assembly, but
that doesn't help me much here.
I'm trying to create a module that creates 5 queries (that a report is
based on) based on a table that the user defines. My tables are named
by date (not my choice), for example:
-ArchivedActions 05-20-05 Everything involving that seems fine.
I'm getting a syntax error at the line marked with a asterik, and I
feel like I've tried everything. Anything obvious that any of you can
spot?
P.S. No one in my office knows a thing about Access.
THANKS!
Option Compare Database
Sub UpdateMatrixQue ries()
Dim Tbl As String
Dim strQueryName As String
Dim qryDef As QueryDef
Dim strSQL As String
Dim dbs As Database
Set dbs = CurrentDb()
cmdRequestDate_ Click
Tbl = "-ArchivedActions " & txtDate
strQueryName = "Matrix - MLBUSA Related Other"
dbs.QueryDefs.D elete strQueryName
strSQL = "SELECT " & Tbl & ".[ActionID], " & Tbl & ".[Quarter New], " _
& Tbl & ".[Quarter Close], " & Tbl & ".[Category], " _
& Tbl & ".[ActionType], " & Tbl & ".[Status], " _
& Tbl & ".[Past Due], " & Tbl & ".[Due Date], " _
& Tbl & ".[Revised Due Date] FROM " & Tbl & " " _
& "WHERE (((" & Tbl & ".[Category]) Like '*BUSA Related*') And " _
& "((" & Tbl & ".[ActionType])='Other')) Or " _
& "(((" & Tbl & ".[Category]) Like '*BUSA related*') And " _
& "((" & Tbl & ".[ActionType])='Other'));"
* Set qryDef = dbs.CreateQuery Def("strQueryNa me", strSQL)
strQueryName = "Matrix - MLBUSA Specific Other"
dbs.QueryDefs.D elete strQueryName
strSQL = "SELECT " & Tbl & ".[ActionID], " & Tbl & ".[Quarter New], " _
& Tbl & ".[Quarter Close], " & Tbl & ".[Category], " _
& Tbl & ".[ActionType], " & Tbl & ".[Status], " _
& Tbl & ".[Past Due], " & Tbl & ".[Due Date], " _
& Tbl & ".[Revised Due Date] FROM " & Tbl & " " _
& "WHERE (((" & Tbl & ".[Category]) Like '*BUSA Specific*') And " _
& "((" & Tbl & ".[ActionType])='Other')) Or " _
& "(((" & Tbl & ".[Category]) Like '*BUSA specific*') And " _
& "((" & Tbl & ".[ActionType])='Other'));"
Set qryDef = dbs.CreateQuery Def("strQueryNa me", strSQL)
strQueryName = "Matrix - MLBUSA Related Significant"
dbs.QueryDefs.D elete strQueryName
strSQL = "SELECT " & Tbl & ".[ActionID], " & Tbl & ".[Quarter New], " _
& Tbl & ".[Quarter Close], " & Tbl & ".[Category], " _
& Tbl & ".[ActionType], " & Tbl & ".[Status], " _
& Tbl & ".[Past Due], " & Tbl & ".[Due Date], " _
& Tbl & ".[Revised Due Date] FROM " & Tbl & " " _
& "WHERE (((" & Tbl & ".[Category]) Like '*BUSA Related*') And " _
& "((" & Tbl & ".[ActionType])='Significant' )) Or " _
& "(((" & Tbl & ".[Category]) Like '*BUSA related*') And " _
& "((" & Tbl & ".[ActionType])='Significant' ));"
Set qryDef = dbs.CreateQuery Def("strQueryNa me", strSQL)
strQueryName = "Matrix - MLBUSA Specific Significant"
dbs.QueryDefs.D elete strQueryName
strSQL = "SELECT " & Tbl & ".[ActionID], " & Tbl & ".[Quarter New], " _
& Tbl & ".[Quarter Close], " & Tbl & ".[Category], " _
& Tbl & ".[ActionType], " & Tbl & ".[Status], " _
& Tbl & ".[Past Due], " & Tbl & ".[Due Date], " _
& Tbl & ".[Revised Due Date] FROM " & Tbl & " " _
& "WHERE (((" & Tbl & ".[Category]) Like '*BUSA Specific*') And " _
& "((" & Tbl & ".[ActionType])='Significant' )) Or " _
& "(((" & Tbl & ".[Category]) Like '*BUSA specific*') And " _
& "((" & Tbl & ".[ActionType])='Significant' ));"
Set qryDef = dbs.CreateQuery Def("strQueryNa me", strSQL)
strQueryName = "MLBUSA Specific Significant Issue & Plan"
dbs.QueryDefs.D elete strQueryName
strSQL = "SELECT " & Tbl & ".[ActionID], " & Tbl & ".[AuditName], " &
Tbl & ".[Category], " _
& Tbl & ".[ActionType], " & Tbl & ".[Status], " _
& Tbl & ".[Past Due], " & Tbl & ".[Due Date], " _
& Tbl & ".[Revised Due Date], SnapActions.Fin ding, " _
& "SnapActions.Re commendation_1, SnapActions.Man ager, " _
& "SnapActions.Ma nagerResponsibl e, SnapActions.Ind RespDept, " _
& "SnapActions.St atusComments FROM " & Tbl & " " _
& "LEFT JOIN SnapActions ON " & Tbl & ".ActionID = SnapActions.Act ionID
" _
& "WHERE (((" & Tbl & ".[Category]) Like '*BUSA Specific*') " _
& "AND ((" & Tbl & ".[ActionType])='Significant' ) " _
& "AND ((" & Tbl & ".[Status])='Open')) OR (((" & Tbl & ".[Category]) "
_
& "Like '*BUSA specific*') AND ((" & Tbl &
".[ActionType])='Significant' ) " _
& "AND ((" & Tbl & ".Status)='open '));"
Set qryDef = dbs.CreateQuery Def("strQueryNa me", strSQL)
Set dbs = Nothing
End Sub
Private Sub cmdRequestDate_ Click()
Dim dteDate As String
dteDate = InputBox("Pleas e enter the date listed at the end" _
& " of the filename of the table you wish to use. Please" _
& " use the format MM-DD-YY and click OK.")
txtDate = dteDate
End Sub