As previously stated twice I believe you need a semi colon after each item.
Add a debug.print line to understand why
You still have not answerred the question as to what type of listbox is this?
is it a value list listbox or a listbox based on a query?
we are just guessing its a value list but i suspect it isnt.
try this
then copy and paste the result from the immediate window here so we can see what we are dealing with.Code:Private Sub Addtolist_Click() debug.print vol_my_worked_hrs.RowSource End Sub
the title to your question
are you trying to save the changes to a table?Changes in listbox dont go into the database. Why?
what do you mean by "dont go into the database"?
Hi,
What do you mean by "Add a debug.print line for the right side of the equals sign before that line.
Run the code and look at the result in the immediate window."
I was afraid you wouldn't understand this and that's why I made suggestion in post #13 for msgbox.What do you mean by "Add a debug.print line for the right side of the equals sign before that line.
Have you tried that?
Following on from davegri's comment, I had to search back to my first reply in post #2 for that (written on 2nd April - over 3 weeks ago)
Your original code from post #1 and repeated in post #17 was as below (with a Debug.Print line added by me)
Adding a Debug.Print line sends the output to the Immediate window which is found in the VB Editor.Code:Private Sub Addtolist_Click() vol_my_worked_hrs.RowSource = vol_my_worked_hrs.RowSource & MyText1 & MyText2 & ";" Debug.Print vol_my_worked_hrs.RowSource & MyText1 & MyText2 & ";" End Sub
This is very useful for developers to find out what is happening in parts of their code.
As Davegri mentioned, a message box is a convenient alternative
MsgBox "vol_my_worked_hrs.RowSource & MyText1 & MyText2 & ";""
Run the code with the Debug.Print line, then copy the information shown in the Immediate window in your next reply
Alternatively replace the Debug line with a message box & do a screengrab of what is shown
As mentioned several times, I believe you need a semicolon after strText1 (though I may be wrong)
Only by seeing your output (as described above) or by you testing that idea can this thread make much progressCode:vol_my_worked_hrs.RowSource = vol_my_worked_hrs.RowSource & ";" & MyText1 & ";" & MyText2
Finally this worked
Me.My_Worked_hrs.AddItem Me.MyText1
Me.My_Worked_hrs.AddItem Me.MyText2
This is a second list My_Worked_hrs box. The first one vol_my_worked_hrs was a combo box converted to a list box.
I have to send this to the database. How do do I do that? Have looked around but havent found a better one yet.
Thanks anyway.
@ijared,
I have beel following your thread. You have been helped by two very knowledgable people, ridders52 & davegri, each with over 1000 posts; moke123 also seems knowledgable.
To receove good, applicable responses, you need to answer questions asked of you. But you seem very good at not answering when question asked of you.
moke123 asked questions in Post # 15 which you ignored; questions were asked again in Post #17 - again ignored.
(pretty much the same questions I have)
So the title of your thread is:
Changes in listbox doen't go into the database. Why?
You started talking about HOW you are trying to do something, but never explaining WHAT you are doing...... two very different things.
What I can gather is:
* You have a list box
* The Row Source of the list box is a value list.
* You expect additions to the list box value list to be saved - not sure where yet.
Just curious....Do you have code to check that MyText1 and/or MyText2 are NOT NULL and/or NOT an Empty String??
So explain what you mean "doen't go into the database"???
From post #21
What is this??
"Sent this to the database" - do you mean save the value list to a table?
If you expect the additions to the list box to be saved somewhere, then you are using the wrong method.
There should/would be a table to store the data for the list box. Code would be used to append (add) the new data (MyText1 & MyText2) to a table.
A query (based on the table) would be the Row Source of the list box. Then the data additions would be "saved to the database".
-------------------------------------------------------------------------------------------------------------
My post is NOT to burn/chastise you but to try and explain why it is taking so long (21 posts and counting) to try and resolve your questions.
The better you are at explaining and providing info, the easier it is to provide a (hopefully) valid solution.
I suggested that in post#9 however you said it didnt work.Finally this worked
Me.My_Worked_hrs.AddItem Me.MyText1
Me.My_Worked_hrs.AddItem Me.MyText2
Ling indicated in post# 10 that this data would not be saved with this method.
Bear in mind that we cannot see what you are working with, which is why we ask questions.
now lets try to resolve your issue with saving the data to a table.
Describe as best you can what the relevant tables look like and what type of form your working with.
Even better is to post a stripped down sample of you database with just the relevant tables and forms.
I'got it working. I convert a combobox to a listbox and that must be a reason why nothing was going in. Now I have to figure out how to save this data evrtime data is put in..
Probably not as both use the exact same syntaxI convert a combobox to a listbox and that must be a reason why nothing was going in
there is no need to have 2 posts for this question especially if you ignore questions. (for some reason chrome wont let me link to your question "listbox doesn't populate")
if your intent is to save this data to your database you are going in the wrong direction.
you should be saving data to a table and if you want to DISPLAY the data in a list box you would use the table/query as the data source of your list box.