kiwidancer
Programmer
Hello,
I am using VBA to query data from Access.
I have figured out that I am getting this error anytime the query needs to return a line that has the value of 0 in column 17.
The values are indeed 0, not null or blank and the same query works fine when I use MSQuery - the error only comes up when it needs to return the information to Excel.
My code for the query looks like this:
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:="ODBC; DSN=MS Access Database; DBQ=\\SERVIDOR\CELUPAL55\CELUPAL55.mdb; DriverId=25;FIL=MS Access; MaxBufferSize=2048; PageTimeout=5;", Destination:=Range(rng)).QueryTable
.CommandText = "SELECT * FROM MonthInvoices WHERE (`Invoice Date`>=20091201 And `Invoice Date`<=20091231)
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = False
.Refresh BackgroundQuery:=False
End With
if I change the .CommandText line to:
.CommandText = "SELECT * FROM MonthInvoices WHERE (`Func Unit Cost`<>0) AND (`Invoice Date`>=20091201 And `Invoice Date`<=20091231)
then I get no error.
Is there any way to SET the cast specification to what I want it to be? Or some other workaround to include these lines as my report is not correct without them?
Thank you in advance for any help!
I am using VBA to query data from Access.
I have figured out that I am getting this error anytime the query needs to return a line that has the value of 0 in column 17.
The values are indeed 0, not null or blank and the same query works fine when I use MSQuery - the error only comes up when it needs to return the information to Excel.
My code for the query looks like this:
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:="ODBC; DSN=MS Access Database; DBQ=\\SERVIDOR\CELUPAL55\CELUPAL55.mdb; DriverId=25;FIL=MS Access; MaxBufferSize=2048; PageTimeout=5;", Destination:=Range(rng)).QueryTable
.CommandText = "SELECT * FROM MonthInvoices WHERE (`Invoice Date`>=20091201 And `Invoice Date`<=20091231)
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = False
.Refresh BackgroundQuery:=False
End With
if I change the .CommandText line to:
.CommandText = "SELECT * FROM MonthInvoices WHERE (`Func Unit Cost`<>0) AND (`Invoice Date`>=20091201 And `Invoice Date`<=20091231)
then I get no error.
Is there any way to SET the cast specification to what I want it to be? Or some other workaround to include these lines as my report is not correct without them?
Thank you in advance for any help!