troubleshooting Question

Adding a Field - error in value

Avatar of ca1358
ca1358 asked on
Microsoft AccessMicrosoft Excel
5 Comments1 Solution54 ViewsLast Modified:
Adding Field 5 name Concatenation --Text getting error Syntax error.   This is the value I added  cell. Offset(0, 5).Value & "',")

Here all the code:
Const dbConStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\DTCHYB-ILSP001\C_MTG_Groups\Mandatory\Analysts - Working Files\Carol\Expert\LSB_analysis.accdb;Persist Security Info=False;"

Sub CopyToAccess()
Dim ws As Worksheet
Dim dbConn As Object
Dim dbCmd As Object
Dim lr As Long
Dim rng As Range, cell As Range

Set ws = Sheets("Sales_Summary")
lr = ws.Cells(Rows.Count, "BA").End(xlUp).Row
Set rng = ws.Range("BA1:BA" & lr)

Set dbConn = CreateObject("ADODB.Connection")
Set dbCmd = CreateObject("ADODB.Command")

On Error GoTo ErrHandler
dbConn.ConnectionString = dbConStr
dbCmd.ActiveConnection = dbConn
On Error GoTo 0

For Each cell In rng
   On Error GoTo DataNotInserted
   dbCmd.CommandText = "INSERT INTO Daily_Historical_Bid_Log (Trade_Date,Trade_Month,ClientID,Client,Tape_Amt,Concatenation) VALUES (" & _
                     "#" & cell.Value & "#," & _
                     "'" & cell.Offset(0, 1).Value & "'," & _
                     cell.Offset(0, 2).Value & "," & _
                     "'" & cell.Offset(0, 3).Value & "'," & _
                     cell.Offset(0, 4).Value & ")"
                     cell.Offset(0, 5).Value & "',")
Next cell
MsgBox "Data has been successfully inserted into Access Table.", vbInformation, "Done!"
Exit Sub

MsgBox "Record is not inserted." & vbNewLine & Err.Number & vbNewLine & Err.Description
MsgBox "Something went wrong, unable to connect to the Access Database. " & vbNewLine & _
       Err.Number & vbNewLine & Err.Description

End Sub
Get vaccinated; Social distance; Wear a mask

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Top Expert 2014

The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros