Update list box

P

Prohock

I have a form to update a list box. Everything works well but the user must
hit "enter" after imputing a new item or the value will not be updated in the
list box. All edits to list box work, but new fields require the "enter" key
to be pressed. How can I program the "enter" key in VB in a close button. So
far I have tried the following:

Private Sub Command4_Click()
DoCmd.Restore
Forms("frmVictim").lstVictim.Requery
DoCmd.Close
End Sub
 
J

Jeff Boyce

I'm unclear on what you are trying to do...

Listboxes are predefined lists of items... why would you want a user to add
a "new field"? (this implies adding new columns ... did you mean to add a
new value?)

If the listbox contains valid values, and you allow a user to add a new
value, how do you know/text to make sure it isn't just a previously listed
value, but misspelled?

You've described "how" you are trying to do something, but not "what". If
you'll explain a bit more about what you are trying to accomplish, folks
here may be able to offer more specific suggestions.

--

Regards

Jeff Boyce
Microsoft Access MVP

Disclaimer: This author may have received products and services mentioned in
this post. Mention and/or description of a product or service herein does
not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
 
P

Prohock

Jeff Boyce said:
I'm unclear on what you are trying to do...

Listboxes are predefined lists of items... why would you want a user to add
a "new field"? (this implies adding new columns ... did you mean to add a
new value?)

If the listbox contains valid values, and you allow a user to add a new
value, how do you know/text to make sure it isn't just a previously listed
value, but misspelled?

You've described "how" you are trying to do something, but not "what". If
you'll explain a bit more about what you are trying to accomplish, folks
here may be able to offer more specific suggestions.

--

Regards

Jeff Boyce
Microsoft Access MVP

Disclaimer: This author may have received products and services mentioned in
this post. Mention and/or description of a product or service herein does
not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.




.
 
P

Prohock

Sorry for the confussion.

The user is able to add a new value, not a new field.

Once the value is entered in the "List Item Edit Form" I would like the new
value to be displayed in the corresponding list box when the user closes the
"List Item Edit Form". The "List Item Edit Form" opens from a button that is
located in the form with the corresponding listbox.

Everything works if the user hits the "enter" key after imputing thier value
in the "List Item Edit Form". Otherwise, the form containing the listbox must
be closed and opened again before the new value will appear in the list box.

I would like to programatically add a "enter" key in the VBA so that the
value appears without having to close and reopen the form containing the list
box.
 
M

Mike Painter

Prohock said:
Sorry for the confussion.

The user is able to add a new value, not a new field.

Once the value is entered in the "List Item Edit Form" I would like
the new value to be displayed in the corresponding list box when the
user closes the "List Item Edit Form". The "List Item Edit Form"
opens from a button that is located in the form with the
corresponding listbox.

Everything works if the user hits the "enter" key after imputing
thier value in the "List Item Edit Form". Otherwise, the form
containing the listbox must be closed and opened again before the new
value will appear in the list box.

I would like to programatically add a "enter" key in the VBA so that
the value appears without having to close and reopen the form
containing the list box.
You can use the not in list property to open a msgbox asking if they want
to add a new value.
If they say yes open a small modal form to gather the (minimal) new
information and add it to the underlaying table.
Then requery the listbox Me.YourListBox.requery to display the updated
information
 
J

Jeff Boyce

That will depend on whether you "feed" the listbox from a table/query (the
preferred approach), or whether you are using a "value list" internal to the
listbox...

--

Regards

Jeff Boyce
Microsoft Access MVP

Disclaimer: This author may have received products and services mentioned in
this post. Mention and/or description of a product or service herein does
not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top