I am trying to format a column from "test" to "TempTable" table.
In test, the data is yymmdd. I need to format this data
into yy/mm/dd (including slashes) and copy to the new TempTable. I have a command button which you would be able to populate when you click on it. However I am getting a "mismatch type" error.
What is wrong with the code? How can I rectify this issue?
I tried and tried but couldn't re-solve it, so I need some help...
Both tables have all "text" fields.
Thanks so much!
************************************************
Public Sub Command0_Click()
Dim db As Database
Dim rec As Recordset
Dim txtAccountNumber, txtCurrency, curAmount, dtDate, tempdtDate, strSQL As String
Set db = CurrentDb()
Set rec = db.OpenRecordset("test"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
DoCmd.SetWarnings False
rec.MoveFirst
While Not (rec.EOF)
curAmount = rec("Field1"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
txtAccountNumber = rec("Field2"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
dtDate = rec("Field3"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
txtCurrency = rec("Field4"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
'Format dtDate with slashes yy/dd/mm
tempdtDate = Left(dtDate, 2) & "/" & Mid(dtDate, 3, 2) & "/" & Right(dtDate, 2)
Debug.Print tempdtDate
strSQL = "INSERT INTO TempTable([Field1],[Field2],[Field3]" & _
"[Field4])" & _
"Values(" & _
"'" & curAmount & "'," & _
"'" & txtAccountNumber & "'," & _
"'" & tempdtDate & "'," & _
"'" & txtCurrency & "'" & _
"
"
rec.MoveNext
Wend
rec.Close
DoCmd.RunSQL (strSQL)
End Sub
In test, the data is yymmdd. I need to format this data
into yy/mm/dd (including slashes) and copy to the new TempTable. I have a command button which you would be able to populate when you click on it. However I am getting a "mismatch type" error.
What is wrong with the code? How can I rectify this issue?
I tried and tried but couldn't re-solve it, so I need some help...
Both tables have all "text" fields.
Thanks so much!
************************************************
Public Sub Command0_Click()
Dim db As Database
Dim rec As Recordset
Dim txtAccountNumber, txtCurrency, curAmount, dtDate, tempdtDate, strSQL As String
Set db = CurrentDb()
Set rec = db.OpenRecordset("test"
DoCmd.SetWarnings False
rec.MoveFirst
While Not (rec.EOF)
curAmount = rec("Field1"
txtAccountNumber = rec("Field2"
dtDate = rec("Field3"
txtCurrency = rec("Field4"
'Format dtDate with slashes yy/dd/mm
tempdtDate = Left(dtDate, 2) & "/" & Mid(dtDate, 3, 2) & "/" & Right(dtDate, 2)
Debug.Print tempdtDate
strSQL = "INSERT INTO TempTable([Field1],[Field2],[Field3]" & _
"[Field4])" & _
"Values(" & _
"'" & curAmount & "'," & _
"'" & txtAccountNumber & "'," & _
"'" & tempdtDate & "'," & _
"'" & txtCurrency & "'" & _
"
rec.MoveNext
Wend
rec.Close
DoCmd.RunSQL (strSQL)
End Sub