S
Suncobra9
These are the messages that came up in order of appearance when I ran this
code.
Once you click Yes you can’t use the Undo command to reverse the changes.
Are you sure you want to append the selected rows?
Microsoft Access has set 0 field(s) to Null due to a type conversion failure
and it didn’t add 1 record(s) to the table due to key violations, 0 record(s)
due to lock violations and 0 record(s) due to validation rule violations. Do
you want to run the action query anyway? To ignore the error(s) and run the
query, click Yes.
For an explanation of the causes of the violations, click Help.
No current record.
What does that mean? It is very different from before. I changed 'rst' to
'Dim rst As DAO.Recordset', which caused the change. If anyone has any ideas,
I'd appretiate it.
Option Compare Database
Option Explicit
Dim strSymbol As String
Dim intRef As Integer
Dim strSQL As String
Dim dteLineDate As Date
Dim rst As DAO.Recordset
Private Sub CopyData()
On Error GoTo Err_CopyData
strSymbol = InputBox("Enter Symbol Code:")
intRef = -63
'Starting value for dteLineDate 1 less than first Raw Data date:
strSQL = "SELECT TOP 1 [RAW DATA].[DATE] AS TopDate FROM [RAW DATA] " & _
"WHERE [RAW DATA].SYMBOL = '" & strSymbol & "'"
Set rst = CurrentDb.OpenRecordset(strSQL)
dteLineDate = rst!TopDate - 1
'Now a loop copies 64 records to Intermediate with ascending
'date and incremented REF:
While intRef < 1
strSQL = "INSERT INTO INTERMEDIATE (SYMBOL, [DATE], HIGH, " & _
"LOW, [LAST], VOLUME) SELECT TOP 1 SYMBOL, [DATE], HIGH, " & _
"LOW, [LAST], VOLUME FROM [RAW DATA] WHERE " & _
"[RAW DATA].SYMBOL = '" & strSymbol & "' AND " & _
"[RAW DATA].[DATE] > #" & dteLineDate & "# " & _
"ORDER BY [RAW DATA].[DATE];"
DoCmd.RunSQL strSQL
strSQL = "SELECT TOP 1 INTERMEDIATE.[DATE] AS ThisDate FROM INTERMEDIATE "
& _
"WHERE (INTERMEDIATE.SYMBOL = '" & strSymbol & "' AND " & _
"INTERMEDIATE.REF IS NULL) ORDER BY INTERMEDIATE.[DATE];"
Set rst = CurrentDb.OpenRecordset(strSQL)
dteLineDate = rst!ThisDate
strSQL = "UPDATE INTERMEDIATE SET REF = " & intRef & _
" WHERE (INTERMEDIATE.SYMBOL = '" & strSymbol & "') AND " & _
"(INTERMEDIATE.[DATE] = #" & dteLineDate & "#);"
DoCmd.RunSQL strSQL
intRef = intRef + 1
Wend
Exit Sub
Err_CopyData:
MsgBox Err.Description
Exit Sub
End Sub
code.
Once you click Yes you can’t use the Undo command to reverse the changes.
Are you sure you want to append the selected rows?
Microsoft Access has set 0 field(s) to Null due to a type conversion failure
and it didn’t add 1 record(s) to the table due to key violations, 0 record(s)
due to lock violations and 0 record(s) due to validation rule violations. Do
you want to run the action query anyway? To ignore the error(s) and run the
query, click Yes.
For an explanation of the causes of the violations, click Help.
No current record.
What does that mean? It is very different from before. I changed 'rst' to
'Dim rst As DAO.Recordset', which caused the change. If anyone has any ideas,
I'd appretiate it.
Option Compare Database
Option Explicit
Dim strSymbol As String
Dim intRef As Integer
Dim strSQL As String
Dim dteLineDate As Date
Dim rst As DAO.Recordset
Private Sub CopyData()
On Error GoTo Err_CopyData
strSymbol = InputBox("Enter Symbol Code:")
intRef = -63
'Starting value for dteLineDate 1 less than first Raw Data date:
strSQL = "SELECT TOP 1 [RAW DATA].[DATE] AS TopDate FROM [RAW DATA] " & _
"WHERE [RAW DATA].SYMBOL = '" & strSymbol & "'"
Set rst = CurrentDb.OpenRecordset(strSQL)
dteLineDate = rst!TopDate - 1
'Now a loop copies 64 records to Intermediate with ascending
'date and incremented REF:
While intRef < 1
strSQL = "INSERT INTO INTERMEDIATE (SYMBOL, [DATE], HIGH, " & _
"LOW, [LAST], VOLUME) SELECT TOP 1 SYMBOL, [DATE], HIGH, " & _
"LOW, [LAST], VOLUME FROM [RAW DATA] WHERE " & _
"[RAW DATA].SYMBOL = '" & strSymbol & "' AND " & _
"[RAW DATA].[DATE] > #" & dteLineDate & "# " & _
"ORDER BY [RAW DATA].[DATE];"
DoCmd.RunSQL strSQL
strSQL = "SELECT TOP 1 INTERMEDIATE.[DATE] AS ThisDate FROM INTERMEDIATE "
& _
"WHERE (INTERMEDIATE.SYMBOL = '" & strSymbol & "' AND " & _
"INTERMEDIATE.REF IS NULL) ORDER BY INTERMEDIATE.[DATE];"
Set rst = CurrentDb.OpenRecordset(strSQL)
dteLineDate = rst!ThisDate
strSQL = "UPDATE INTERMEDIATE SET REF = " & intRef & _
" WHERE (INTERMEDIATE.SYMBOL = '" & strSymbol & "') AND " & _
"(INTERMEDIATE.[DATE] = #" & dteLineDate & "#);"
DoCmd.RunSQL strSQL
intRef = intRef + 1
Wend
Exit Sub
Err_CopyData:
MsgBox Err.Description
Exit Sub
End Sub