colossalUW
Technical User
Hi there,
Access 2000 project
I've tried several iterations of this code (with the help of archived threads), and just can't quite get it to work.
I'm attempting to copy the data from one subform to another if the user chooses yes from a message box.
Basically, the first subform displays Proposed costs for a grant. If the grant status is 'Awarded', then a message box asks the user if they would like to have the Proposed costs entered into the Awarded costs subform.
My thought is to create two recordsets, one from tblCostsProposed and one from tblCostsAwarded, and enter each record from Proposed to Awarded.
When running the below code I get the error message "Item not found in this collection." Any ideas? Thanks much!
Private Sub frmPropSubUp_Exit(Cancel As Integer)
On Error GoTo frmPropSubUp_Exit_Err
'If status is Awarded, then message box asks the user if proposed costs should be entered
'into the actual costs.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim intAns As Integer
Dim rstProp As DAO.Recordset
Dim rstAct As DAO.Recordset
'Checks if status is Awarded, and displays message box if it is
If (Nz(Forms!frmGrantsEntry!GntStatus, "") = "Awarded") Then
intAns = MsgBox("The status of this proposal is Awarded." & _
vbCrLf & " " & _
vbCrLf & "Would you like to enter these Proposed costs into the " & _
"Awarded costs form automatically?" & _
vbCrLf & "If needed, you will be able to change award information " & _
"after performing this action.", vbYesNo, "Awarded Costs:")
'If user chooses No, then sub ends
If intAns = 7 Then
GoTo frmPropSubUp_Exit_Exit
ElseIf intAns = 6 Then
'Create a recordset based on the GC1# entered into the CostsProposed table
Set rstProp = CurrentDb.OpenRecordset("SELECT * FROM tblCostsProposed WHERE [GC1#] = '" & _
Me![GC1#] & "'", dbOpenDynaset)
'Create recordset to hold new entries to CostsActual table
Set rstAct = CurrentDb.OpenRecordset("tblCostsActual", dbOpenDynaset)
'Enter proposed data into actuals table
Do While rstProp.EOF = False
rstAct.AddNew
rstAct![GC1#] = rstProp![GC1#]
rstAct![YRActual] = rstProp![YRProp]
rstAct![DirActual] = rstProp![DirProp]
rstAct![IndAct] = rstProp![IndProp]
rstAct.Update
rstProp.MoveNext
Loop
'Close the recordsets
rstProp.Close
rstAct.Close
'Refresh form so changes are immediately visible
Forms!frmGrantsEntry.Refresh
End If
End If
'Error trap
frmPropSubUp_Exit_Exit:
Exit Sub
frmPropSubUp_Exit_Err:
MsgBox Error$
Resume frmPropSubUp_Exit_Exit
End Sub
Access 2000 project
I've tried several iterations of this code (with the help of archived threads), and just can't quite get it to work.
I'm attempting to copy the data from one subform to another if the user chooses yes from a message box.
Basically, the first subform displays Proposed costs for a grant. If the grant status is 'Awarded', then a message box asks the user if they would like to have the Proposed costs entered into the Awarded costs subform.
My thought is to create two recordsets, one from tblCostsProposed and one from tblCostsAwarded, and enter each record from Proposed to Awarded.
When running the below code I get the error message "Item not found in this collection." Any ideas? Thanks much!
Private Sub frmPropSubUp_Exit(Cancel As Integer)
On Error GoTo frmPropSubUp_Exit_Err
'If status is Awarded, then message box asks the user if proposed costs should be entered
'into the actual costs.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim intAns As Integer
Dim rstProp As DAO.Recordset
Dim rstAct As DAO.Recordset
'Checks if status is Awarded, and displays message box if it is
If (Nz(Forms!frmGrantsEntry!GntStatus, "") = "Awarded") Then
intAns = MsgBox("The status of this proposal is Awarded." & _
vbCrLf & " " & _
vbCrLf & "Would you like to enter these Proposed costs into the " & _
"Awarded costs form automatically?" & _
vbCrLf & "If needed, you will be able to change award information " & _
"after performing this action.", vbYesNo, "Awarded Costs:")
'If user chooses No, then sub ends
If intAns = 7 Then
GoTo frmPropSubUp_Exit_Exit
ElseIf intAns = 6 Then
'Create a recordset based on the GC1# entered into the CostsProposed table
Set rstProp = CurrentDb.OpenRecordset("SELECT * FROM tblCostsProposed WHERE [GC1#] = '" & _
Me![GC1#] & "'", dbOpenDynaset)
'Create recordset to hold new entries to CostsActual table
Set rstAct = CurrentDb.OpenRecordset("tblCostsActual", dbOpenDynaset)
'Enter proposed data into actuals table
Do While rstProp.EOF = False
rstAct.AddNew
rstAct![GC1#] = rstProp![GC1#]
rstAct![YRActual] = rstProp![YRProp]
rstAct![DirActual] = rstProp![DirProp]
rstAct![IndAct] = rstProp![IndProp]
rstAct.Update
rstProp.MoveNext
Loop
'Close the recordsets
rstProp.Close
rstAct.Close
'Refresh form so changes are immediately visible
Forms!frmGrantsEntry.Refresh
End If
End If
'Error trap
frmPropSubUp_Exit_Exit:
Exit Sub
frmPropSubUp_Exit_Err:
MsgBox Error$
Resume frmPropSubUp_Exit_Exit
End Sub