Solved

Compile error on recordset

Posted on 2012-03-14
4
301 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

760 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

20 Experts available now in Live!

Get 1:1 Help Now