?
Solved

Compile error on recordset

Posted on 2012-03-14
4
Medium Priority
?
313 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 2000 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 2000 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

800 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