Re: Updateing a combobox

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: tina (nospam_at_address.com)
Date: 05/11/04


Date: Tue, 11 May 2004 20:07:40 GMT

this is the solution that worked for me. notice that the code is running
from the combo box's NotInList event.

Private Sub Combo0_NotInList(NewData As String, Response As Integer)

    If MsgBox("Do you want to add a new color to the list?",
vbDefaultButton1 + vbYesNo) = vbYes Then
' DoCmd.OpenForm "frmColors", acFormDS, , , acFormAdd, acDialog
        DoCmd.RunMacro "Macro1.open form"
        Response = acDataErrAdded
    Else
        Response = acDataErrContinue
        Me!Combo0 = Null
        Me!Combo0.Dropdown
    End If

End Sub

i commented out the "DoCmd.OpenForm..." line because that did not suspend
the code for me; instead i used the next line to run a macro, settings
below:

Macro object name: Macro1
Macro name: open form
first Action: OpenForm
Form Name: frmColors
View: Datasheet
Data Mode: Add
Window Mode: Dialog
second Action: StopMacro

you could try the "DoCmd.OpenForm..." line first (commenting out the
"DoCmd.RunMacro" line), since that one is supposed to work. if it doesn't
suspend the code, use the other line instead, like i did.
and, of course, you have to substitute your own control, form and macro
names, and msgbox message, etc.

hth

"Tracey" <anonymous@discussions.microsoft.com> wrote in message
news:b43501c4377b$a78cbca0$a401280a@phx.gbl...
> The me.combobox.requery will not work because the value of
> the combobox must be something within the list or empty.
> Lets say you type something in the combobox that is not in
> the list, the "add to" form opens in whatever mode you
> add data and close the form which forces the requery, the
> combobox still has the value that you typed into it (which
> wasn't in the list to begin with), which is not in the
> list yet, an error occurrs because of that. even clearing
> the contents of the combobox generates and error
> because "null" is not in the list? The error is occuring
> because the field cannot requery while text is present. I
> think I understand how to write the code to force the
> requery, I am having trouble clearing data or the new
> record before forcing the requery. Any Ideas?
>
>
>
> >-----Original Message-----
> >I have created a form that has a combox box which has a
> >list of parts. I coded a proc that adds a part to the
> >list If the user types in a part that doesn't exist in
> the
> >list. This opens another form in which the user inputs
> >additional info and then closes. The new part is now in
> >the list however the combobox does not show the new item
> >yet, and the combobox has the new part number (from when
> >the user typed it in to begin with). I wrote code that
> >when the user changes records then the combobox will
> >requery and the new item will be there. Unfortunatley I
> >would prefer to have the combo box requery and and the
> >user select the new part without leaving the record. Any
> >ideas? I searched the newsgroups and didn't find anything
> >similar, I can't imiagine that I am the only one that has
> >had this problem. As always, I appreciate the help!
> >Tracey
> >.
> >



Relevant Pages

  • Re: ListBox/ComboBox Acting as Macro/Hyperlink Tool
    ... When I reset the VBA editor, and then select in the ComboBox, ... Private Sub ComboBox1_Click ... It could do with some error handling for cases when the macro or hyperlink ... "hlink" does not be dimmed; ...
    (microsoft.public.excel.programming)
  • Re: Increment question
    ... Requery then Show the new value. ... If you used a macro 'To add that record': ... In the action field type SetValue ... between the "Private Sub Form_Load" and the 'End Sub Line ...
    (microsoft.public.access.forms)
  • Re: Updateing a combobox
    ... > Private Sub Combo0_NotInList ... instead i used the next line to run a macro, ... >> the combobox must be something within the list or empty. ... >> because the field cannot requery while text is present. ...
    (microsoft.public.access.formscoding)
  • Re: ListBox/ComboBox Acting as Macro/Hyperlink Tool
    ... Private Sub ComboBox1_Click ... It could do with some error handling for cases when the macro or hyperlink ... It looks like your combobox is called "Combobox1". ... "hlink" does not be dimmed; ...
    (microsoft.public.excel.programming)
  • Re: Update Table - Newbie needs help
    ... to requery the combo so it knows about the new company. ... Private Sub Form_AfterUpdate ... Tips for Access users - http://allenbrowne.com/tips.html ... > How can I refresh the data in the combobox after creating ...
    (microsoft.public.access.formscoding)