I
injanib via AccessMonster.com
Hi all,
I can't figure out what the problem is with the following procedure. It is
supposed to look a table and determine if an entry already exist for a value
entered in a combo box and ask to add if a record doesn't already exist. The
problem is that no matter what it will add a new entry in the table. Even if
I select an entry from the combo box, it adds a duplicate record. It does
however promps if the entry is a new value and doesn't already exist in the
table. Any help is appriciated.
here is the code.
Private Sub cboCustomer_AfterUpdate()
Dim rst As Recordset
If DCount("*", "CustomerTable", "Customer = '" & Forms!Contract.cboCustomer
& "'") < 1 Then
If MsgBox("Do you want the database to save this new customer?", vbYesNo,
"Add New Customer?") = vbYes Then
Me.cboCustomer = StrConv(Me.cboCustomer, 3)
Set rst = CurrentDb.OpenRecordset("CustomerTable")
With rst
.AddNew
!Customer = Me![cboCustomer]
.Update
.Close
End With
Set rst = Nothing
Me.cboCustomer.Requery
Else
Me.txtCompany.SetFocus
End If
Else
Exit Sub
Me.txtCompany = Me.cboCustomer.Column(2)
Me.txtCell = Me.cboCustomer.Column(3)
Me.txtEmail = Me.cboCustomer.Column(4)
Me.txtAddress = Me.cboCustomer.Column(5)
Me.txtCity = Me.cboCustomer.Column(6)
Me.txtCountry = Me.cboCustomer.Column(7)
End If
End Sub
I can't figure out what the problem is with the following procedure. It is
supposed to look a table and determine if an entry already exist for a value
entered in a combo box and ask to add if a record doesn't already exist. The
problem is that no matter what it will add a new entry in the table. Even if
I select an entry from the combo box, it adds a duplicate record. It does
however promps if the entry is a new value and doesn't already exist in the
table. Any help is appriciated.
here is the code.
Private Sub cboCustomer_AfterUpdate()
Dim rst As Recordset
If DCount("*", "CustomerTable", "Customer = '" & Forms!Contract.cboCustomer
& "'") < 1 Then
If MsgBox("Do you want the database to save this new customer?", vbYesNo,
"Add New Customer?") = vbYes Then
Me.cboCustomer = StrConv(Me.cboCustomer, 3)
Set rst = CurrentDb.OpenRecordset("CustomerTable")
With rst
.AddNew
!Customer = Me![cboCustomer]
.Update
.Close
End With
Set rst = Nothing
Me.cboCustomer.Requery
Else
Me.txtCompany.SetFocus
End If
Else
Exit Sub
Me.txtCompany = Me.cboCustomer.Column(2)
Me.txtCell = Me.cboCustomer.Column(3)
Me.txtEmail = Me.cboCustomer.Column(4)
Me.txtAddress = Me.cboCustomer.Column(5)
Me.txtCity = Me.cboCustomer.Column(6)
Me.txtCountry = Me.cboCustomer.Column(7)
End If
End Sub