R
RFrechette
Any help with this would be greatly apprecidated.
My form called frm_PVD_02 is filtered by parameters from frm_PVD_subform.
Each record in frm_PVD_02 has a checkbox next to it (Control Name = Chk_Add).
When the SAVE button is clicked on frm_PVD_02, if the field called Chk_Add =
-1, that record is inserted into a table called tbl_PVD_Updates. Each record
in the frm_PVD_02 form has an ID which is part of the data inserted to the
tbl_PVD_Updates table.
This is the code I use (with much help from this forum) and it works
beautifully.
Dim strSQL As String
Dim strSQL1 As String
Dim RsC As DAO.Recordset
Set RsC = Me.RecordsetClone
RsC.MoveFirst
While Not RsC.EOF
Me.Bookmark = RsC.Bookmark
If Chk_Add = -1 And txt_HV_Discount <> 0 Then
strSQL = "INSERT INTO [tbl_PVD_Updates](AcctNo, ItemNo, ProjectNo, Date_PVD,
Charge_Units, Unitpr, Rprice, HV_Discounts, SpecPricing, ID_Updates)" & _
"select" & "'" & txt_AcctNo & "'," & "'" & txt_ItemNo_Real & "'," & "'" &
txt_ProjectNo & "'," & "'" & _
txt_Date_PVD & "'," & "'" & ([txt_Actual Units]) & "'," & "'" & txt_Unitpr &
"'," & "'" & _
[Forms]![frm_PVD]![frm_PVD_02].Form![txt_rprice] & "'," & "'" &
txt_HV_Discount & "'," & "'" & txt_SpecPricing & "'," & "'" & txt_ID_oss_tran
& "';"
DoCmd.RunSQL strSQL
End If
RsC.MoveNext
Wend
Me.Requery
Set RsC = Nothing
------------------------
Now the problem I’m having:
If I’ve checked off all the records I want and save them to the
tbl_PVD_Updates table, and then I need to uncheck one of the records and save
again: How do I delete the record that no longer should be in the
tbl_PVD_Updates table?
I tried many variations of the following code:
strSQL1 = "DELETE * " & _
"FROM tbl_PVD_Updates " & _
"WHERE tbl_PVD_Updates.ID_Updates = " &
[Forms]![frm_PVD]![frm_PVD_02].[Form]![ID_oss_tran] & _
"AND [Forms]![frm_PVD]![frm_PVD_02].[Form]![Chk_Add] = 0"
DoCmd.RunSQL strSQL1
I put this code in front of the “If Chk_Add = -1 And txt_HV_Discount <> 0
Then†line within the While statement, but I end up with a continuous loop
(or so it seems).
I hope I've explained this well enough. Can anyone help me? I’m sure it’s
something so simple, I should know it, but I haven’t been using VB for very
long and have no programming experience.
Thank you in advance.
Rachel
My form called frm_PVD_02 is filtered by parameters from frm_PVD_subform.
Each record in frm_PVD_02 has a checkbox next to it (Control Name = Chk_Add).
When the SAVE button is clicked on frm_PVD_02, if the field called Chk_Add =
-1, that record is inserted into a table called tbl_PVD_Updates. Each record
in the frm_PVD_02 form has an ID which is part of the data inserted to the
tbl_PVD_Updates table.
This is the code I use (with much help from this forum) and it works
beautifully.
Dim strSQL As String
Dim strSQL1 As String
Dim RsC As DAO.Recordset
Set RsC = Me.RecordsetClone
RsC.MoveFirst
While Not RsC.EOF
Me.Bookmark = RsC.Bookmark
If Chk_Add = -1 And txt_HV_Discount <> 0 Then
strSQL = "INSERT INTO [tbl_PVD_Updates](AcctNo, ItemNo, ProjectNo, Date_PVD,
Charge_Units, Unitpr, Rprice, HV_Discounts, SpecPricing, ID_Updates)" & _
"select" & "'" & txt_AcctNo & "'," & "'" & txt_ItemNo_Real & "'," & "'" &
txt_ProjectNo & "'," & "'" & _
txt_Date_PVD & "'," & "'" & ([txt_Actual Units]) & "'," & "'" & txt_Unitpr &
"'," & "'" & _
[Forms]![frm_PVD]![frm_PVD_02].Form![txt_rprice] & "'," & "'" &
txt_HV_Discount & "'," & "'" & txt_SpecPricing & "'," & "'" & txt_ID_oss_tran
& "';"
DoCmd.RunSQL strSQL
End If
RsC.MoveNext
Wend
Me.Requery
Set RsC = Nothing
------------------------
Now the problem I’m having:
If I’ve checked off all the records I want and save them to the
tbl_PVD_Updates table, and then I need to uncheck one of the records and save
again: How do I delete the record that no longer should be in the
tbl_PVD_Updates table?
I tried many variations of the following code:
strSQL1 = "DELETE * " & _
"FROM tbl_PVD_Updates " & _
"WHERE tbl_PVD_Updates.ID_Updates = " &
[Forms]![frm_PVD]![frm_PVD_02].[Form]![ID_oss_tran] & _
"AND [Forms]![frm_PVD]![frm_PVD_02].[Form]![Chk_Add] = 0"
DoCmd.RunSQL strSQL1
I put this code in front of the “If Chk_Add = -1 And txt_HV_Discount <> 0
Then†line within the While statement, but I end up with a continuous loop
(or so it seems).
I hope I've explained this well enough. Can anyone help me? I’m sure it’s
something so simple, I should know it, but I haven’t been using VB for very
long and have no programming experience.
Thank you in advance.
Rachel