Additem for ListBox

  • Thread starter Thread starter Mac
  • Start date Start date
M

Mac

I just created a form which has part number box, a ok button and listbox

User will enter part number in there and then will click on ok button.

Once part number is found in database , I want the data to be displayed in
the listbox for that particular part number only. I want to display,
quantity_on_hand, Price, etc.

I am new to this VBA/VB and would really appreciate if some kindly send me
syntax for adding data to the list box.

Thanks
 
Hi,
as you have a table with data you want to show in a listbox (as i understand
you) - then best way is to add new data to a table using insert query, and
then requery listbox. of course listbox should have this table (or query
based on it) as a row source. sample code:

Private Sub cmdAdd_Click

currentdb.execute "Insert into MyTable (myField) Values('" & me.Textbox1 &
"')"
me.listbox1.requery

end sub

HTH
 
Mac said:
I just created a form which has part number box, a ok button and
listbox

User will enter part number in there and then will click on ok button.

Once part number is found in database , I want the data to be
displayed in the listbox for that particular part number only. I
want to display, quantity_on_hand, Price, etc.

I am new to this VBA/VB and would really appreciate if some kindly
send me syntax for adding data to the list box.

You wouldn't normally use AddItem for this. Instead, set the
RowSourceType property of your list box to "Table/Query", and set the
RowSource property to a query that selects the fields you want to see
from the appropriate table, and which uses the part-number text box as a
criterion, so that the query returns only the records that match that
part number. The reference to the text box on the form (in the query's
criteria) will have the general format
"[Forms]![YourFormName]![PartNumber]", where "YourFormName" is the name
of the form, and "PartNumber" is the name of the text box where the user
will enter the part number.

Once you've got the list box set up this way, the only code you need in
your OK button's Click event is a requery of the list box (to make it
show the corresponding records). For example,

Private Sub cmdOK_Click()

Me!lstPartDetails.Requery

End Sub

where "cmdOK" is the name of the command button, and "lstPartDetails" is
the name of the list box.
 
Mac said:
I just created a form which has part number box, a ok button and
listbox

User will enter part number in there and then will click on ok button.

Once part number is found in database , I want the data to be
displayed in the listbox for that particular part number only. I
want to display, quantity_on_hand, Price, etc.

I am new to this VBA/VB and would really appreciate if some kindly
send me syntax for adding data to the list box.

Thanks

I just noticed that you cross-posted this question to
<microsoft.public.fox.vfp.forms>, though I read your message in
<microsoft.public.access.modulesdaovba>. Are you asking about Access
forms, or FoxPro forms? They are completely different. My answer was
based on the understanding that you are using Access.
 
I am sorry, my mistake. We have an accounting package which allows us use
VBA to modify or create new forms.

I can select the record and save it in cursor but I dont know how to put
those records in the listbox.

Suppose my cursor name is csrtest and if I try to display thru the message
box :
msgbox csrtest.part_description
it displays the right part's description but I have about 4 other columns
that I need to display.

I need to know how to add cursor record to listbox and display.

Thanks
 
Mac said:
I am sorry, my mistake. We have an accounting package which allows
us use VBA to modify or create new forms.

I can select the record and save it in cursor but I dont know how to
put those records in the listbox.

Suppose my cursor name is csrtest and if I try to display thru the
message box :
msgbox csrtest.part_description
it displays the right part's description but I have about 4 other
columns that I need to display.

I need to know how to add cursor record to listbox and display.

What is this accounting package? Is it based on Microsoft Access? I am
told that Simply Accounting is, for example. But I have to wonder,
because the term "cursor" isn't normally used in Access, though it is
used in other database systems. I don't want to give you advice that
would work for Access, but won't work for your software.

Also, in Access a list box is normally used to display multiple records.
You seem to be talking about using a list box to display a single
record. Am I misunderstanding you, or are you using odd terminology, or
are we really talking about a completely different control?
 
Back
Top