:banghead:
Good Morning I am new at Access/VBA and this forum
I get a run-time error 13 type mismatch error when I Dim OriginationDate As Date. Code runs fine when Dim OriginationDate As String
Any ideas?
'Option Explicit
Dim KRFcon As ADODB.Connection
Dim KRFrs As ADODB.Recordset
Dim vrefnum As Double
Dim KRFsCon, KRFsSQL, vTable, datacol, L, datavalue As String
Dim Author As String
Dim Area As String
Dim Comments1 As String
Dim id As String
Dim Newid As String
Dim OriginationDate As Date
' Open a connection.
Set KRFcon = New ADODB.Connection
KRFsCon = "Provider=SQLOLEDB;Data Source=kpesmnsql201;Initial Catalog=KRFSiteServices;Integrated Security=SSPI"
'MsgBox (DRsCon)
KRFcon.Open KRFsCon
Set KRFrs = New ADODB.Recordset
' Make a query over the connection and find the last ID add one to create the new RecordID
KRFsSQL = "select top 1 [ID] from krfdatabase order by [id] DESC"
KRFrs.Open KRFsSQL, KRFcon, adOpenStatic, adLockBatchOptimistic, adCmdText
currentID = KRFrs.Fields(0).Value
Newid = currentID + 1
KRFrs.Close
' Date service request is made
OriginationDate = Format$(Now(), "mm/dd/yyyy hh:mm")
MsgBox (OriginationDate)
'This populates all data from form to SQL
KRFsSQL = "insert into krfdatabase ([Author], [Area], [comments1], [OriginationDate]"
KRFsSQL = KRFsSQL + ") VALUES (" + "'" + Author + "'" + "," + "'" + Area + "'" + "," + "'" + Comments1 + "'" + "," + "'" + OriginationDate + "'"
KRFsSQL = KRFsSQL + ")"
MsgBox "Record #" + [Newid] + " was created"
KRFrs.Open KRFsSQL, KRFcon, adOpenKeyset, adLockBatchOptimistic, adCmdText 'update a record
Good Morning I am new at Access/VBA and this forum
I get a run-time error 13 type mismatch error when I Dim OriginationDate As Date. Code runs fine when Dim OriginationDate As String
Any ideas?
'Option Explicit
Dim KRFcon As ADODB.Connection
Dim KRFrs As ADODB.Recordset
Dim vrefnum As Double
Dim KRFsCon, KRFsSQL, vTable, datacol, L, datavalue As String
Dim Author As String
Dim Area As String
Dim Comments1 As String
Dim id As String
Dim Newid As String
Dim OriginationDate As Date
' Open a connection.
Set KRFcon = New ADODB.Connection
KRFsCon = "Provider=SQLOLEDB;Data Source=kpesmnsql201;Initial Catalog=KRFSiteServices;Integrated Security=SSPI"
'MsgBox (DRsCon)
KRFcon.Open KRFsCon
Set KRFrs = New ADODB.Recordset
' Make a query over the connection and find the last ID add one to create the new RecordID
KRFsSQL = "select top 1 [ID] from krfdatabase order by [id] DESC"
KRFrs.Open KRFsSQL, KRFcon, adOpenStatic, adLockBatchOptimistic, adCmdText
currentID = KRFrs.Fields(0).Value
Newid = currentID + 1
KRFrs.Close
' Date service request is made
OriginationDate = Format$(Now(), "mm/dd/yyyy hh:mm")
MsgBox (OriginationDate)
'This populates all data from form to SQL
KRFsSQL = "insert into krfdatabase ([Author], [Area], [comments1], [OriginationDate]"
KRFsSQL = KRFsSQL + ") VALUES (" + "'" + Author + "'" + "," + "'" + Area + "'" + "," + "'" + Comments1 + "'" + "," + "'" + OriginationDate + "'"
KRFsSQL = KRFsSQL + ")"
MsgBox "Record #" + [Newid] + " was created"
KRFrs.Open KRFsSQL, KRFcon, adOpenKeyset, adLockBatchOptimistic, adCmdText 'update a record