Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo boxes, adding LNAME and FNAME to tbl if NEW

Status
Not open for further replies.

Sisco

Technical User
Jul 11, 2000
12
0
0
US
Hello!
The OnNotInList Combo box code below is from Dev Ashish, The Access Web, and it works great to add one new record to a table (tblSO_Name), but how can I modify the code below to add LNAME and FNAME as a new record? Suppose you have several "Smiths", but none with FNAME = "John". Once the last name and first name have both been selected or typed in (FNAME will have to be typed in if it's not there and obviously if LNAME isn't there, add both as new record to tbl_NAME), these two names will be added as one new record.
I'm getting a bit flustered with this one, and I know it's probably something simple ...

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

Dim db As Database, rs As Recordset
Dim strMsg As String
strMsg = "'" & NewData & "' is not an available AE Name"
strMsg = strMsg & "@Do you want to associate the new Name to the current DLSAF?"
strMsg = strMsg & "@Click Yes to link or No to re-type it."
If MsgBox(strMsg, vbQuestion + vbYesNo, "Add new name?") = vbNo Then
Response = acDataErrContinue
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("tblSO_Name",dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!SO_FName = NewData
rs.Update
If Err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContinue
Else
Response = acDataErrAdded
End If
End If
End Sub
 
Create a popup form that will add as many records as you want. I have a simular situation on an application that I use. On the NotInList event I ask the user if they want to add it. If they say yes, then my code opens a model popup form that allows them to add as many as they wish. lcjohnson@kawvalley.org
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top