Hello,
I built a form that has an Append Button that helps me to add records to a table. The code that I have works very well (see below code) but I would like to add additional step to it. Once the user clicked on the append button once, I would like to add a code that would prevent/stop the user from clicking on this button for the second time to prevent the duplicate data being added to the table that this button is linked to. Can some one please help me to write this part of code?
Private Sub AppendContractsCommand_Click()
Dim db As Database
Dim rs As Recordset
Dim rs2 As Recordset
Dim itm, contractID, contractname As Variant
Dim contract() As String
Set db = CurrentDb()
Set rs = db.OpenRecordset("ChecksApplied")
For Each itm In [cboContract ID].ItemsSelected
contract() = Split([cboContract ID].ItemData(itm), ", ")
For Each contractID In contract()
Set rs2 = db.OpenRecordset("SELECT * FROM [Contacts] WHERE [Contract ID] = '" & contractID & "'")
contractname = rs2![Contract Name]
rs.AddNew
rs![Contract ID] = contractID
rs![Payment ID] = [Payment ID]
rs![Parent Company ID] = [cboParentCompanyID]
rs![Company Name] = contractname
rs.Update
Next
Next
rs.Close
rs2.Close
Set rs = Nothing
Set rs2 = Nothing
Set db = Nothing
Thanks for your help.
I built a form that has an Append Button that helps me to add records to a table. The code that I have works very well (see below code) but I would like to add additional step to it. Once the user clicked on the append button once, I would like to add a code that would prevent/stop the user from clicking on this button for the second time to prevent the duplicate data being added to the table that this button is linked to. Can some one please help me to write this part of code?
Private Sub AppendContractsCommand_Click()
Dim db As Database
Dim rs As Recordset
Dim rs2 As Recordset
Dim itm, contractID, contractname As Variant
Dim contract() As String
Set db = CurrentDb()
Set rs = db.OpenRecordset("ChecksApplied")
For Each itm In [cboContract ID].ItemsSelected
contract() = Split([cboContract ID].ItemData(itm), ", ")
For Each contractID In contract()
Set rs2 = db.OpenRecordset("SELECT * FROM [Contacts] WHERE [Contract ID] = '" & contractID & "'")
contractname = rs2![Contract Name]
rs.AddNew
rs![Contract ID] = contractID
rs![Payment ID] = [Payment ID]
rs![Parent Company ID] = [cboParentCompanyID]
rs![Company Name] = contractname
rs.Update
Next
Next
rs.Close
rs2.Close
Set rs = Nothing
Set rs2 = Nothing
Set db = Nothing
Thanks for your help.