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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't add new record to combo box?

Status
Not open for further replies.

jlnewbie

Technical User
Aug 9, 2000
69
I kmow that this is a FAQ, But I can't seem to add a new record to my combo box. Right now my combo box has five values in its list (as a lookup). I want the user to add to this list when necessary. Ive copied this code from MVPS.org/access. I also tried the Solutions DB event to add a record, but no luck. This is the code below. It seems I'm on the right track but I lost from the point where I get the error messages

Do I just add this code to the Not In List Event or do add it to somewhere else? Do I change any other properties in the table or form. Im also I'm confused about Limit to List Property of the table. Do I set it to Yes? Please be gentle I'm still new to this. Please explain as much as you can

Thanks.

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

Dim db As Database, rs As Recordset
Dim strMsg As String
strMsg =
 
It seems that my code was cut off. Here is the code
Private Sub CuringDays_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("CuringDays", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!AEName = NewData
rs.Update

If Err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContinue
Else
Response = acDataErrAdded
End If
End If
End Sub
 
If I understand correctly, it looks like using a DLookup function might help you here.

DLookup(expr, domain[, criteria])

From this, I'm not sure of the technique, and I'm interested in learning any experienced advice. I'd likely try calling an add new combo box item procedure and requery the combo boxes recordsource after the main form is reactivated.

hth,
Drew


 
You have to remember that you need to update the object's view. The Recordset object has no connection to the bound Recordset of the form. Use the requery, and after that a DataErrContinue. If you are interested, mail this adress and I will return an example of what I did to make it work.

hhmoeller
 
Ups! i forgot the email: hhmoeller@image.dk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top