Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT INTO statement (data not showing correctly)

Status
Not open for further replies.

tincan56

MIS
Feb 18, 2002
24
US
Hi. I am really stuck with an issue. I am trying to insert date from an orginal table to another table within the same database.

However, with the INSERT INTO SQL statements that I have is not giving the correct data from the orginal table. Both orignal table and the new table have text field.

I would really appreciate for any suggestions and help!

**************Here is the VBA/SQL code.
Dim db As Database
Dim rec As Recordset
Dim strSQL As String
Dim dtBillingStart, dtBillingEnd As Date
Dim i As Integer
Dim dtTemp As Date
Dim dtBillingMonth
Dim intBlanketNum As String

Set db = CurrentDb()
Set rec = db.OpenRecordset("GRS Detail")

rec.MoveFirst
While Not (rec.EOF)

intBlanketNum = rec("Blanket Number")


For i = 0 To DateDiff("m", dtBillingStart, dtBillingEnd)
DoCmd.SetWarnings False
dtTemp = DateAdd("m", i, dtBillingStart)

strSQL = " INSERT INTO TempTable([Blanket Number]) Values(" & intBlanketNum & ") "
MsgBox (intBlanketNum)

DoCmd.RunSQL (strSQL)

Next i
rec.MoveNext
Wend

rec.Close
End Sub

*********This is what I am getting in the results in the new table - and I am not too sure where these numbers came from.
934
933
682
688

*********This is the data from the original table.
1003-302
1003-312
1003-326
1003-341
 
Hi,

Is [Blanket Number] a string (text) in your database? If that's the case then the INSERT statement should contain extra quotes and should look like this:

strSQL = " INSERT INTO TempTable([Blanket Number]) Values('" & intBlanketNum & "') "

Bye,
Danny.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top