0

Ok I am trying to programmatically generate records for an access database, but it keeps displaying like a macro and the line of code in question shows up in red. What am I doing wrong?

Sub arrayData()
Dim custnames() As Varient
Dim num As Integer, dbs As Database, InsertRecord As String
Dim CustId As Integer, num1 As Integer
Dim CustName As String
Set dbs = CurrentDb()
CustId = 0
For num1 = 0 To 9
CustId = CustId + 1
custnames = Array("Peter", "Mary", "Frank", "Ian", "Ron", "Natalie","Radhu", "Jat", "David")
num = Int((9 - 0 + 1) * Rnd + 0)
// ERROR OCCURS ON THE LINE BELOW.
InsertRecord = "insert into CUSTOMER(CustNo,CustFName)values("&"'"&CustId&"'"&","&"'"&CustName&"'"&")"
dbs.Execute InsertRecord
Debug.Print CustId; CustName
End Sub

EDIT: Added & after CustName

1
  • You're missing an & after CustName Commented Apr 24, 2017 at 7:15

1 Answer 1

1

Try to write readable string concatenations. And, as CustId is numeric, no quotes:

InsertRecord = "insert into CUSTOMER (CustNo,CustFName) values (" & CustId & ",'" & CustName & "')"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.