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!

Update table through combobox 1

Status
Not open for further replies.

BeffyMar

Programmer
Jul 20, 2000
17
0
0
US
I have a combo box on a form that lists names from a table.&nbsp;&nbsp;If the user adds a name that is not on the list then I want that name to be added to the table automatically.&nbsp;&nbsp;I cant seem to code the onNotInList properly.&nbsp;&nbsp;Any suggestions would be greatly appreciated...<br><br>THanks in advance<br>Mary Beth
 
pls check FAQ area of &quot;Access- General dicussion&quot;, there're two ways to get what you want to do...<br>1) Combobox - Allow a user to add values to the underlying table<br>2) Combobox - Allow a user to add values to the underlying Value List<br><br>Hope this would help YOU... <p>Mohamed Aly<br><a href=mailto:samara_79@hotmail.com>samara_79@hotmail.com</a><br><a href= > </a><br>
 
this is an example of the code that you could use, i derived it from one of the FAQs in the General discussion forum:<br><b><br>Private Sub <font color=red>ComboBoxName</font>_NotInList(NewData As String, Response As Integer)<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim iAnswer As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim db As Database, rst As Recordset<br><br>&nbsp;&nbsp;&nbsp;&nbsp;iAnswer = MsgBox(&quot;Item is not currently in list, adding item&quot;, _<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vbOKCancel + vbQuestion)<br>&nbsp;&nbsp;&nbsp;&nbsp;If iAnswer = vbOK Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Me.Source.Value = NewData<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set db = CurrentDb<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set rst = db.OpenRecordset(&quot;<font color=red>TableName</font>&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rst.AddNew<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rst.Fields(&quot;<font color=red>FieldName</font>&quot;) = NewData<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rst.Update<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Response = acDataErrAdded<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>End Sub<br></b><br><br>just change the red to fit your app.<br>ps.&nbsp;&nbsp;the Limit To List property must be set to Yes <p>Brian Famous<br><a href=mailto:bfamous@ncdoi.net>bfamous@ncdoi.net</a><br><a href= > </a><br>
 
Thanks I like this one more... I will use it..<br>
 
i am a different person than the one that started this but i'm using this code. the code keeps failing on the DIM db As Database statment. it says user defined type not defined. any clues. i'm not a programmer at all so don't even know what to look for.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top