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!

Adding to Not in List for combo box, but not displayed in table? 1

Status
Not open for further replies.

seawave

Technical User
Oct 21, 2002
30
US
I have a combo box with values from a table. I want to be able to have my users add values to the table via the combo box on my form.
I have changed the "LimitToList" property to No. This allows me to type a value in the combo box without getting an error message, BUT, the value does not write
back to the field in the table that is tied to the combo
box.

I saw the Not In List event on the property sheet, but I am
new to coding and did not know how to write the code, assuming that would fix my problem.

My combo box is called "Contact number". My table is called
"Contacts".

Any help would be greatly appreciated.
 
***Code to add.

Note the code between * *. This is where you will have to add names to suit your particular scenario. Remove the *. These are only there to help you identify the changes you will need to make, but leave “” etc, if present, as these are very important. There are two parts of the code you will need to alter.
*********************************************************
I read the info in the link, but am not understanding the
above information I read in the newsletter.

What do the *s represent?
Again, thank you for the help.
 
Here's what you need to do:

01) Rename your combobox to "cboContactNumber"
02) Rename your table to "tblContacts"
03) Copy the code below to the code section on your form
04) Make sure that you have a reference set to one of the DAO libraries (2.0 - 3.6). This is under Tools | References when you are in the "coding" section of your form.

Private Sub cboContactNumber_NotInList(NewData as String, Response as Integer)

Dim sMSG As String
Dim iAnswer As Integer
Dim thisDB As Database
Dim thisRS as Recordset

sMSG = "" & NewData & " is not currently in your Contacts list. Would you like to add this person?"

iAnswer = MsgBox( sMSG, vbOKCancel + vbQuestion )

If iAnswer = 1 Then 'They want to add it
Set thisDB = CurrentDB
Set thisRS = thisDB.OpenRecordSet("tblContacts")

With thisRS
.AddNew
!ContactName = NewData 'This is the field in your table
.Update
End With

Response = acDataErrAdded
Else
Response = acDataErrDisplay
End If

End Sub



***********
If you have anymore questions, let me know.

RS
 
Elysium,
Thanks for your help. I will give this a try.

Again, thank you for your time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top