[AccessD] Combo Subform Entries

Hollis,Virginia HollisVJ at pgdp.usec.com
Tue Nov 18 14:09:40 CST 2003


I have a combobox on a main form that is used to select certain records on
the subform. For example, if you select Car from the combo, the subform
shows all the records for Car.
 
I need to be able to add an entry to the combobox on the main form & have it
available for use to add new records. So if I add Jeep to the NotInList
event of the combobox, Jeep would be in the list, the Combo would show Jeep,
& the subform should be blank & ready to add new entries for Jeep.
 
I tried Requery, I tried a seperate form for adding new entries to the list,
and OnClose of the form, requery the form, but nothing works. The entry is
in the list, but the subform stays on the previous selections entry. Or
should the requery go on the After Update of the Combo?
 
Virginia
 
On NotInList
 
    ' Return Control object that points to combo box.
    Set ctl = Me!cboLocation
    ' Prompt user to verify they wish to add new value.
    If MsgBox("Would you like to add '" & NewData & "' to the list?",
vbYesNo, "Add New Name") = vbYes Then
        ' Set Response argument to indicate that data is being added.
        Response = acDataErrAdded
        ' Add string in NewData argument to table.
        NewData = DoConv(NewData)
        strSQL = " INSERT INTO tbl_Location ( Location ) SELECT '" &
DoConv(NewData) & "'"
        DoCmd.SetWarnings False
        DoCmd.RunSQL strSQL
        ctl.Value = NewData
        DoCmd.SetWarnings True
   
    Else
        ' If user chooses Cancel, suppress error message and undo changes.
        Response = acDataErrContinue
        ctl.Undo
    End If



More information about the AccessD mailing list