Linq,
Both the methods you have told me does not append new values to record. It still replaces the old value.
How would you add new record to the table?
The confusion is here is caused by your use of the "Append" word.
when you say append, we normally understand it as replacing the old value.
So if I understand it correctly, you want to add a new value in the combo box right? meaning, the old value will stay unchanged, and the new value becomes a new choice in the list?
you just need to requery. But requery only that field and not the whole form.
this are my suggestions.
That combo box field you have there, format it as limit to list = Yes
so that if a user types a new data which is not yet in the list, they would not be able to change or append that old value currently selected.
then create an unboun form where a user can add a new value to the list.
details:
(assuming your combo box is bound to a table that contains the choices in the combobox)
add an 'On DblClick' and 'On Not in List' event procedure to that combo box field.
let's say your combo box field is named [comboDescription]
add a vba code to the OnNotinList event.
- Private Sub comboDescription_NotInList(NewData As String, Response As Integer)
-
MsgBox "Text you entered is not in the List" & _
-
vbCrLf & "Double Click to Add a new Descripton.", , "Error!"
-
Response = DataErrCont
-
End Sub
when a user types in a new value in the combo box which is not yet on the list of choices (not yet in the table where the combo box is bound to), then
access would prompt the user saying that what they typed in is not in the list.
Then that message box would also tell them that to add that value, they must
double click the combo box.
Now, you create an unbound form to let the user add a new description in the combobox.
This unbound form would have a textbox bound to the descriptions table, then two command buttons. one for add/save, and one for cancel.
Have this unbound form's property set to Date Entry = Yes
Then the 1st command button, let's say an "Add" button should command
access to save whatever the user types in the text box to the table of the descriptions.
So the OnClick event procedure of the add button is something like this:
(Let's say the orginal form is named "frmProducts" and the unbound form is named "frmAddDescription")
- Private Sub cmdAdd_Click()
-
If IsNull(Me![Description]) Then
-
MsgBox "There is no Description to Add." & _
-
vbCrLf & "Please click Cancel to Close the Form.", _
-
vbInformation, "Add a Description"
-
Else
-
DoCmd.RunCommand acCmdSaveRecord
-
DoCmd.Close acForm, "frmAddDescription", acSaveYes
-
Forms![frmProducts]![comboDescription].Requery
-
End If
-
End Sub
The other button in the unbound form is the cancel button that just closes
the unbound form. you may use the wizard for this.
Now lets go back to the original form "frmProducts".
After adding that NotInList event.
we will now add the "On Dbl Click" event.
- Private Sub comboDescription_DblClick(Cancel As Integer)
-
Me![comboDescription] = ""
-
DoCmd.OpenForm "frmDescription"
-
End Sub
There you go, your issue is resolved. The scenario would be like this.
The user opens your form 'frmProducts' then input information, now
the user needs to select a description of the product from the combobox
'comboDescription'.
Unfortunately, the combo box does not have the description the user is looking for for this product. therefore he types a new one in the combobox.
since the description he typed is not in the list, a message box appears
saying "Text you entered is not in the list. Double click to add a new description"
so the user clicks ok on the message box then of course, follows what the message box said. The user double clicks the combo box.
This would open the unbound form 'frmAddDescription' without closing the current form.
now on the unbound form, the user types that new description in the text box and clicks the "Add" button.
this closes the unbound form and the focus goes back to the original form.
When the user click the down arrow of the combo box, he will now see the
new description he entered in the unbound form and selects that. :)
Hope this would help.