Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Compile error on recordset

Posted on 2012-03-14
4
Medium Priority
?
316 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

636 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