Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run time error '1004' using TextBox1.Text as SQL query criteria

I get "Run time error '1004' SQL Syntax Error" when running the following VBA:

Sub CommandButton1_Click()

With ActiveSheet.QueryTables.Add(Connection:= _

"ODBC;DSN=Springbrook2;UID=ODBCUSER;HOST=millbrae3 ;PORT=26102;DB=ssi.db;", _
Destination:=Range("A1"))
.CommandText = Array( _
"SELECT GL_History_0.Ref_Batch_No, GL_History_0.Ref_Batch_Month,
GL_History_0.Ref_Batch_Year, GL_Journal_Entry_0.JE_Date,
GL_Journal_Entry_0.System, GL_History_0.Acct_1, GL_History_0.Acct_2,
GL_History" _
, _
"_0.Acct_3, GL_History_0.Acct_4, GL_Journal_Entry_0.Description,
GL_History_0.CR_Amount, GL_History_0.DR_Amount" & Chr(13) & "" & Chr(10) &
"FROM PUB.GL_History GL_History_0, PUB.GL_Journal_Entry GL_Journal_Entry_0" &
Chr(13) & "" & Chr(10) & "WHERE GL_Hist" _
, _
"ory_0.Journal_Entry = GL_Journal_Entry_0.Journal_Entry AND
((GL_Journal_Entry_0.System='UB') AND (GL_Journal_Entry_0.JE_Date={d
TextBox1.Text}))" _
)
.Name = "Springbrook UB Interface 3-27-08"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False


End With

End Sub

The debugger highlights the ".Refresh BackgroundQuery:=False".
Upon clicking the "CommandButton1", I'm trying to have the macro connect to
a pre-defined database query ("Springbrook UB Interface 3-27-08"). What I am
also toying with is having the user enter the effective date in the UserForm1
TextBox1.Text field as criteria for the query. I think that may be where I
might be having a problem. Any suggestions are appreciated. Thank you!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
run time error 1004 general odbc error excel 2003 vba Mentos Excel Programming 5 January 24th 11 02:56 PM
Run Time 1004 Error: Application or Object Difine Error BEEJAY Excel Programming 0 October 17th 06 10:45 PM
Web Query Error 1004 - Cannot insert columns... Steach91[_3_] Excel Programming 1 January 8th 06 02:10 PM
run-time error '1004': Application-defined or object-deifined error [email protected] Excel Programming 5 August 10th 05 09:39 PM
Help with error 1004 in database query Alex Zhang Excel Programming 1 August 14th 04 12:46 AM


All times are GMT +1. The time now is 05:40 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"