Add record to primary table using transation form.

G

Guest

I have a from that auto populates customer details when the customer ID is
entered. At the moment, it work only if a customer ID exists in the primary
customer table. If a customer ID is not recognised, Access prompts a message
stsing that the ID does not exist. The customer ID is a primary ke.

Is it possible to enter a new record i.e. customer id, customer name,
customer address etc in a transaction form and program Access to save the
information into the primary customers table instead of having to refer back
to the primary customers table to create a new customer record?
 
N

noodnutt

G'day Allana

This may help you, it is used in a ComboBox, when it updates, it should auto
generate the CustID if you have that field set to AutoNumber, now the only
problem you will have is that it only updates that field in the table.

One of the many MVP Guru's may be able to assist you further.

Private Sub txtCustomerName_NotInList(NewData As String, Response As
Integer)

Dim db As Database, rs As Recordset, strMsg As String

strMsg = NewData & " is not listed ! Do you want to add it to the list of
Customers ?"
If MsgBox(strMsg, vbQuestion + vbYesNo, "Add New Customer?") = vbNo Then
Response = acDataErrContinue
Else
Set db = CurrentDb()
Set rs = db.OpenRecordset("tblYourTable", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!CustomerName = NewData
rs.Update
If Err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContinue
Else
Response = acDataErrAdded
End If
End If

Good luck

HTH

Mark.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top