I have a spreadsheet pulling information from an Access database. I use a form to get input from the user, then use the input to build the WHERE part of a SQL query. This is how the query reads:
With oQryTable
.CommandText = Array( _
"SELECT CJE.Department, CJE.Account, CJE.Debits, CJE.Credits, CJE.Journal_Number, CJE.Journal_Period, CJE.Acct_Type" _
& Chr(13) & "" & Chr(10) _
& "FROM `C:\Bogus\Access\CJE`.CJE CJE" _
& Chr(13) & "" & Chr(10) _
& "WHERE " & sWhere _
& Chr(13) & "" & Chr(10) _
, _
"ORDER BY CJE.Journal_Number"
sWhere is built from the form choices.
Range("SQL_WHERE" = "(CJE.Department='" & sDept & "') AND (CJE.Account='" & sAccount & "') AND (CJE.Journal_Period='" & sDate & "')"
When the choice for sDept is 9050.CJE, sDate is APR, and sAccount is AP.2014, the query works. If sAccount is changed to AdminFee.50001000, I receive Run Time Error 13, Type Mismatch. Have I exceeded some sort of length constraint for the statement? It seems if I pick an account with a short name, the query will work. Long names and it bombs.
With oQryTable
.CommandText = Array( _
"SELECT CJE.Department, CJE.Account, CJE.Debits, CJE.Credits, CJE.Journal_Number, CJE.Journal_Period, CJE.Acct_Type" _
& Chr(13) & "" & Chr(10) _
& "FROM `C:\Bogus\Access\CJE`.CJE CJE" _
& Chr(13) & "" & Chr(10) _
& "WHERE " & sWhere _
& Chr(13) & "" & Chr(10) _
, _
"ORDER BY CJE.Journal_Number"
sWhere is built from the form choices.
Range("SQL_WHERE" = "(CJE.Department='" & sDept & "') AND (CJE.Account='" & sAccount & "') AND (CJE.Journal_Period='" & sDate & "')"
When the choice for sDept is 9050.CJE, sDate is APR, and sAccount is AP.2014, the query works. If sAccount is changed to AdminFee.50001000, I receive Run Time Error 13, Type Mismatch. Have I exceeded some sort of length constraint for the statement? It seems if I pick an account with a short name, the query will work. Long names and it bombs.