Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 17th, 2003, 05:46 AM
Lee Miles Lee Miles is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 7 Lee Miles User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Syntax error in INSERT INTO query

I am writing a VB6 program that interacts with a ms access 97 database. I have an APPEND query in access that works OK and want to run this query from VB. The code below returns a "syntax error" but I cannot for the life of me see the problem.

The code below is firstly a simplified query to test if the INSERT INTO is working .... It fails! and below that is the full query which also fails! Any help greatly appreciated.


Private Sub cmdRoster_Click()
Dim adoUmpiresRS, adoFixturesRS, adoPlaying1RS, adoPlaing2RS As Recordset

Dim SQLtext As String
Dim db As New Connection

Set adoUmpiresRS = New Recordset
Set adoFixturesRS = New Recordset
Set adoPlaying1RS = New Recordset
Set adoPlaying2RS = New Recordset
Set adoFixturesRS = New Recordset
Set adoconstraintsrs = New Recordset

With db
'áppfilepath contains the path & filename
' the open statement works OK without error
.Open "PROVIDER=MSDataShape;Data PROVIDER=" & _
"Microsoft.Jet.OLEDB.4.0;Data Source=" _
& appfilepath

' this SELECT query works OK & returns the correct number
' of records
adoUmpiresRS.Open "SELECT apoolID,club,grade,sex FROM [a pool list]", db, adOpenDynamic, adLockOptimistic

' heres the simplified append query that has a syntax error
.Execute "INSERT INTO constraints ([ApoolID]) VALUES ('9999')", recs, adExecuteNoRecords

'HERES THE ACTUAL QUERY THAT RUNS OK IN ACCESS97
'construct the append query text
SQLtext = "INSERT INTO Constraints ( ApoolID, datefrom, timefrom, dateto, timeto, datenotified, notifiedby )" _
& " SELECT [A pool list].ApoolID, Fixtures.date, [time]-#12/30/1899 1:0:0# AS starttime, Fixtures.date, [time]+#12/30/1899 0:15:0# AS finishtime, Now() AS today, ""Auto"" AS notifby " _
& "FROM [A pool list] RIGHT JOIN Fixtures ON ([A pool list].sex = Fixtures.sex) AND ([A pool list].grade = Fixtures.grade) AND ([A pool list].club = Fixtures.club1);"

'run the append query - but it has a syntax error in VB
db.execute SQLtext,recs,adExececuteNoRecords


Thankyou

Reply With Quote
  #2  
Old December 17th, 2003, 07:58 AM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,178 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 56 m 45 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
why the parentheses?
__________________
Fisherman

"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein

Reply With Quote
  #3  
Old December 17th, 2003, 08:45 PM
Lee Miles Lee Miles is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 7 Lee Miles User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy why parethesis?

The parenthesis [] around field names in the query are generated by ms access97 and were copied from the sql view in the query editor and pasted into vb6 code.

I put paretnthesis around the field name in the simplified query just in case the field name was a reserved vb word. Either way (with or without parenthesis) the query still returns a "syntax error"

Reply With Quote
  #4  
Old December 17th, 2003, 09:32 PM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,178 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 56 m 45 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
hmm... confrusing - I've never messed with table constraints in VB before... I'm perplexed

Reply With Quote
  #5  
Old December 17th, 2003, 11:44 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,982 Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level)Doug G User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 18 h 42 m 27 sec
Reputation Power: 814
My guess is the Now() function is causing the problem. When you execute the query from within Access, Now() is recognized as a function. However, when you pass the SQL through ADO from ASP, Now() is not recognized as a valid SQL term since it's an Access-specific function.

Reply With Quote
  #6  
Old December 18th, 2003, 08:20 AM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,178 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 56 m 45 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
well... I thought it was the statement above that one that he was having the problem with though

Reply With Quote
  #7  
Old December 19th, 2003, 07:37 AM
Lee Miles Lee Miles is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 7 Lee Miles User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile Found the problem!

Thanks for your advice guys, I finally found the syntax problem (don't I feel like a goose!). below is the code as I've ammedied it, you'll see that I've enclosed the table name "constraints" in parenthesis [] because it seems that "constraints" is a reserved VB6 word and you ned to tell VB that it's a table name and not the reserved word function your using. The now() function in the VB query works fine!

'----------------------------------------------------------------
'Use APPEND query to add dates & times when umpires are playing
'to the constraints file in the database
'---------------------------------------------------------------
' N.B. warmup time = 1 hr & warm down time = 15 min
frmRoster.ProgressBar1.Value = 30 'two thirds done
frmRoster.text1.Text = "Writing when umpires are playing"
Set adoConstraintsRS = New ADODB.Recordset
adoConstraintsRS.CursorType = adOpenKeyset
adoConstraintsRS.LockType = adLockOptimistic
'contraints inside [] becasue its a VB6 reserved word
SQLtext = "INSERT INTO [Constraints] ( ApoolID, datefrom, timefrom, dateto, " _
& "timeto, datenotified, notifiedby ) SELECT [A pool list].ApoolID, " _
& "Fixtures.date, [time]-#12/30/1899 1:0:0# AS starttime, Fixtures.date, " _
& "[time]+#12/30/1899 0:15:0#+#1:15:00# AS finishtime, Now() AS today, ""Auto"" AS " _
& "notifby FROM [A pool list] RIGHT JOIN Fixtures ON (([A pool list].club " _
& "= Fixtures.club1) OR ([A pool list].club = Fixtures.club2)) AND " _
& "([A pool list].grade = Fixtures.grade) AND ([A pool list].sex = Fixtures.sex);"
'run the APPEND query & show user the progress
adoConstraintsRS.Open SQLtext, db, , , adCmdText
frmRoster.text1.Text = "Sucessfully updated constraints file"

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Syntax error in INSERT INTO query


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT