By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,107 Members | 1,323 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,107 IT Pros & Developers. It's quick & easy.

Concatenation produces calculation instead of concatentation

P: n/a
Greetings,

I'm using the procedure below to insert records into a table which contains a
field (SalesOrder) that must be in the format

8-1
8-2
8-3
8-4

etc.

I placed a MsgBox statement to see the concatenation result which seems correct
but when I look at the result in the table I get

7
6
5
4

The results of a calculation!! I tried various ways using the CStr function
with no success.
8-1= 7
8-2 = 6
8-3 = 5
8-4 = 4

Private Sub cmdInsertRecords_Click()
Dim dbs As DAO.Database
Dim intStart As Integer
Dim intEnd As Integer
Dim intMonth As Integer
Dim intCounter As Integer

intStart = Me.txtStart
intEnd = Me.txtEnd
intMonth = Me.txtMonth

Set dbs = CurrentDb

For intCounter = intStart To intEnd
dbs.Execute " INSERT INTO tblInvoices " & _
"(SalesOrder) Values " & _
"(" & intMonth & " - " & intCounter & ");"

MsgBox intMonth & "-" & intCounter

Next intCounter

dbs.Close
Set dbs = Nothing

End Sub

Any ideas would be appreciated.

Thanks

Ed Marzan
NYC
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
If you want SQL to recognize a string as such, you must surround it with
quotes or single quotes.
Here's one way you could try:

dbs.Execute " INSERT INTO tblInvoices " & _
"(SalesOrder) Values " & _
"('" & intMonth & " - " & intCounter & "');"

HTH
- Turtle
"Ducojansen" <du********@aol.com> wrote in message
news:20***************************@mb-m15.aol.com...
Greetings,

I'm using the procedure below to insert records into a table which contains a field (SalesOrder) that must be in the format

8-1
8-2
8-3
8-4

etc.

I placed a MsgBox statement to see the concatenation result which seems correct but when I look at the result in the table I get

7
6
5
4

The results of a calculation!! I tried various ways using the CStr function with no success.
8-1= 7
8-2 = 6
8-3 = 5
8-4 = 4

Private Sub cmdInsertRecords_Click()
Dim dbs As DAO.Database
Dim intStart As Integer
Dim intEnd As Integer
Dim intMonth As Integer
Dim intCounter As Integer

intStart = Me.txtStart
intEnd = Me.txtEnd
intMonth = Me.txtMonth

Set dbs = CurrentDb

For intCounter = intStart To intEnd
dbs.Execute " INSERT INTO tblInvoices " & _
"(SalesOrder) Values " & _
"(" & intMonth & " - " & intCounter & ");"

MsgBox intMonth & "-" & intCounter

Next intCounter

dbs.Close
Set dbs = Nothing

End Sub

Any ideas would be appreciated.

Thanks

Ed Marzan
NYC

Nov 12 '05 #2

P: n/a
Hi Turtle

Thanks for the reply. Your suggestion worked perfectly.

Interesting... I also received an email with your response from
developersindex.com. Can anyone explain how that works?

In article <fn*******************@newsread2.news.atl.earthlin k.net>,
"MacDermott" <ma********@mindspring.com> writes:
Subject: Re: Concatenation produces calculation instead of concatentationFrom: "MacDermott" <ma********@mindspring.com>
Date: Sat, 20 Sep 2003 10:56:11 GMT

If you want SQL to recognize a string as such, you must surround it with
quotes or single quotes.
Here's one way you could try:

dbs.Execute " INSERT INTO tblInvoices " & _
"(SalesOrder) Values " & _
"('" & intMonth & " - " & intCounter & "');"

HTH
- Turtle

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.