SQL statements

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have some code that looks like this

for i = 1 to Form_frmRecordViewer.lstData.ListCount - 1

sqlstring = "INSERT INTO Labels ([ItemNumber]) VALUES ( " &
Form_frmRecordViewer.lstData.Column(1, count) & " ) "

next

I have two problems. When I have data like 0001-A it asks for a parameter
list for A but what I want to do is for Labels.ItemNumber to contain 0001-A
not just 1

Second it doesn't like values like A 1.47 in the SQL statement:

Any help would be appreciated

Thanks
 
Rather than
VALUES ( " & Form_frmRecordViewer.lstData.Column(1, count) & " ) "
Try
VALUES ( ' " & Form_frmRecordViewer.lstData.Column(1, count) & " ' ) "
**Remove the space between single and double quotes. I left them in for
clarity**

When you are concatentating text/string variables into an SQL statement, you
need to bracket them with single quotes or the SQL statement will expect a
number. That's why it doesn't "like" 0001-A. It tries to do a subtraction
and asks you what A is.

(Not sure why it doesn't like 1.47. Maybe a TypeMismatch? Are you sure
ItemNumber is a text field and not a non-decimal number data type like
Integer or Long? If it is, it won't like 0001-A any better when you clarify
the string/number issue.

HTH,
 
Back
Top