By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,652 Members | 1,995 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,652 IT Pros & Developers. It's quick & easy.

I need some help with a query

P: 65
Hi, I've build this query in VBA so it was easy to use lots af variables. But for some reason I can't get it to work properly. I'm searching on this for the last 2 hours and i'm getting desperate.

Expand|Select|Wrap|Line Numbers
  1.  db.Execute ("INSERT INTO tmpOverzicht(eadnr, naam, voornaam, geslacht, leeftijd, gewicht, lengte, BMI, fvc, fev) VALUES (" & rst.Fields(0).Value & "," & cstr(rst.Fields(1).Value) & "," & cstr(rst.Fields(2).Value) & "," & cstr(rst.Fields(4).Value) & "," & cstr(DateDiff("yyyy", rst.Fields(3).Value, now())) & "," & cstr(rst2.Fields(1).Value) & "," & cstr(rst3.Fields(1).Value) & "," & cstr((rst2.Fields(1).Value / (rst3.Fields(1).Value * rst3.Fields(1).Value))) & "," & cstr(rst4.Fields(0).Value) & "," & cstr(rst4.Fields(1).Value)) & ";")
Greetz
Twanne
Sep 20 '07 #1
Share this Question
Share on Google+
1 Reply


MMcCarthy
Expert Mod 10K+
P: 14,534
When passing strings you will need to surround them with single quotes. You will also have to leave spaces after the commas and after the tablename and before the bracket. You also have to enclose the closing brackets on the VALUES in quotes. Try this out...

Expand|Select|Wrap|Line Numbers
  1.  
  2. db.Execute ("INSERT INTO tmpOverzicht (eadnr, naam, voornaam, geslacht, leeftijd, gewicht, lengte, BMI, fvc, fev) VALUES (" & _
  3. rst.Fields(0).Value & ", '" & CStr(rst.Fields(1).Value) & "', '" & CStr(rst.Fields(2).Value) & "', '" & CStr(rst.Fields(4).Value) & _
  4. "', " & CStr(DateDiff("yyyy", rst.Fields(3).Value, now())) & "', '" & CStr(rst2.Fields(1).Value) & "', '" & CStr(rst3.Fields(1).Value) & "', '" & _
  5. CStr((rst2.Fields(1).Value / (rst3.Fields(1).Value * rst3.Fields(1).Value))) & "', '" & CStr(rst4.Fields(0).Value) & "', '" & CStr(rst4.Fields(1).Value) & "');")
  6.  
Oct 3 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.