Question : adding items to combo boxes on form

Hello,
i attached  code and database example-
the code i use to add items to combo boxes on form.
this database - because I believe may have constructed inaccurately- is not letting me add items to second two combo boxes- is there a way I can change code to let me add items like the first combo box-
if you enter a new name in first combo box - you will see how works-
the second two combo boxes give me errors-
i am hoping since real database is large- i can make the second two combo boxes work without having to redo tables and form
thank you
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
Private Sub cboXCompany_NotInList(NewData As String, Response As Integer)
'Suppress the default error message.

Response = acDataErrContinue

' Prompt user to verify if they wish to add a new value.

If MsgBox("The company of " & NewData & " is not in list. Add it?", vbYesNo) = vbYes Then

' Set Response argument to indicate that data is being added.

'Open a recordset of the tblCompany Table.

Dim db As Database

Dim rstcboCompany As Recordset

Dim sqltblCompany As String

Set db = CurrentDb()

sqltblCompany = "Select * From tblCompany "

Set rstcboCompany = db.OpenRecordset(sqltblCompany, dbOpenDynaset)

'Add a new Company with the value that is stored in the variable NewData.

rstcboCompany.AddNew

rstcboCompany![CompanyName] = NewData

rstcboCompany.Update

'Inform the combo box that the desired item has been added to the list.

Response = acDataErrAdded

rstcboCompany.Close 'Close the recordset

End If





End Sub
Attachments:
 
combo boxes on form
 

Answer : adding items to combo boxes on form

I have no problems with second field - value is added.
You should set "Limit to list" to Yes for third field.
Random Solutions  
 
programming4us programming4us