Solved

Compile error on recordset

Posted on 2012-03-14
4
303 Views
Last Modified: 2012-03-14
I am getting a Compile error Expected: End of statement

at the line that reads
strInsert = "INSERT INTO Temp_Input (LOC) VALUES ('"rs2.Fields(1).Value"');"
with rs2 Highlighted.

Private Sub Command4_Click()
Dim rs2 As New ADODB.Recordset
Dim cnn2 As New ADODB.Connection
Dim cmd2 As New ADODB.Command
Dim strInsert As String

With cnn2
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=Y:\0_Sales_Planning\DataSource\Vendor Attributes\Vendor Agent Attribute\Aegis\Import\Vendor Attribute File Irving Ridgepoint.xls;Extended Properties=""Excel 8.0;HDR=NO;IMEX=1;"";"

.Open
End With

Set cmd2.ActiveConnection = cnn2
cmd2.CommandType = adCmdText
cmd2.CommandText = "SELECT * FROM [Ridge Point MA Sales$]"
rs2.CursorLocation = adUseClient
rs2.CursorType = adOpenStatic
rs2.LockType = adLockReadOnly
rs2.Open cmd2

While Not rs2.EOF
strInsert = "INSERT INTO Temp_Input (LOC) VALUES ('"rs2.Fields(1).Value"');"
Debug.Print strInsert
CurrentDb.Execute strInsert, dbFailOnError

rs2.MoveNext
Wend
End Sub
0
Comment
Question by:Keking
  • 3
4 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 37719448
Try this:

strInsert = "INSERT INTO Temp_Input (LOC) VALUES ('" & rs2.Fields(1).Value & "');"
0
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 500 total points
ID: 37719463
The Value property, btw is the default so you can get by with just this:


strInsert = "INSERT INTO Temp_Input (LOC) VALUES ('" & rs2.Fields(1) & "');"


Also worth noting if you are not already aware - the recordset field's index is zero-based, so rs2.Fields(1) is the second selected column.  rs2.Fields(0) is the first.
0
 

Author Closing Comment

by:Keking
ID: 37719473
Thank you for the quick answers!
0
 
LVL 61

Expert Comment

by:mbizup
ID: 37719478
Glad to help out :)
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Modal form 11 29
Dlookup MSACCESS 5 24
Access Open Report with SQL Parameter 11 28
Cascading Combo boxes between 2 sub navigation forms 1 9
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now