R
Ralph
I am reformating data from table 1 and sending it to table 2 with a button
command. Sometimes I need to delete one or two rows from table 2 and table 1
to create a new updated record with the same primary key. I want to rerun
the button and replace the updated records in table 2. I do not want to
replace all the records. Problem is when I rerun the button I get an Error
3022 and the append to table 2 fails. I'd like it to append the updated
records and ignore those already appended. I suppose I could delete all the
rows from table 1 after the append. Then when I redo a row it would be the
only one in table 1 and it would work. I was thinking to leave the rows that
were okay in table 1, if I do this in a query the duplicates would not append
but the new rows I've recreated would. Office 2003.
If my best option is to simply delete all the rows from table 1 after they
are appended to table 2, how do I do this?
This is the code I am using:
Private Sub btnPage1_Click()
DoCmd.SetWarnings False
On Error GoTo ProcError
Dim strSQL As String
Dim FNSmo As String
FNSmo = MonthName(Me.grpSampleMonth, True) & txtCalYr
strSQL = "INSERT INTO tbl1FNS" & FNSmo & " ( ReviewNo, CaseNo)" _
& "SELECT tblPage1.ReviewNo, Right(0000000000 & [CaseNo],10) AS CaseN " _
& "FROM tblPage1 " _
& "WHERE CInt(Mid([tblPage1].[ReviewNo],2,2)) = " & _
Me.grpSampleMonth
CurrentDb.Execute strSQL, dbFailOnError
MsgBox "The page 1 data is loaded in the FNS database"
DoCmd.SetWarnings True
ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure YourProcedureName..."
Resume ExitProc
End Sub
command. Sometimes I need to delete one or two rows from table 2 and table 1
to create a new updated record with the same primary key. I want to rerun
the button and replace the updated records in table 2. I do not want to
replace all the records. Problem is when I rerun the button I get an Error
3022 and the append to table 2 fails. I'd like it to append the updated
records and ignore those already appended. I suppose I could delete all the
rows from table 1 after the append. Then when I redo a row it would be the
only one in table 1 and it would work. I was thinking to leave the rows that
were okay in table 1, if I do this in a query the duplicates would not append
but the new rows I've recreated would. Office 2003.
If my best option is to simply delete all the rows from table 1 after they
are appended to table 2, how do I do this?
This is the code I am using:
Private Sub btnPage1_Click()
DoCmd.SetWarnings False
On Error GoTo ProcError
Dim strSQL As String
Dim FNSmo As String
FNSmo = MonthName(Me.grpSampleMonth, True) & txtCalYr
strSQL = "INSERT INTO tbl1FNS" & FNSmo & " ( ReviewNo, CaseNo)" _
& "SELECT tblPage1.ReviewNo, Right(0000000000 & [CaseNo],10) AS CaseN " _
& "FROM tblPage1 " _
& "WHERE CInt(Mid([tblPage1].[ReviewNo],2,2)) = " & _
Me.grpSampleMonth
CurrentDb.Execute strSQL, dbFailOnError
MsgBox "The page 1 data is loaded in the FNS database"
DoCmd.SetWarnings True
ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure YourProcedureName..."
Resume ExitProc
End Sub