Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    ijared is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    19

    Question Changes in listbox doen't go into the database. Why?

    This is the data I have and nothing is added when I click Addtolist and don't understand why? Any help?

    Private Sub Addtolist_Click()
    vol_my_worked_hrs.RowSource = vol_my_worked_hrs.RowSource & MyText1 & MyText2 & ";"
    End Sub
    ijared

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    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.
    You should be able to see the reason from that.

    If not paste the result into the listbox row source and view in the form
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    Probably should be:
    Code:
    vol_my_worked_hrs.RowSource = vol_my_worked_hrs.RowSource & MyText1 & ";" & MyText2 & ";"

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Quote Originally Posted by davegri View Post
    Probably should be:
    Code:
    vol_my_worked_hrs.RowSource = vol_my_worked_hrs.RowSource & MyText1 & ";" & MyText2 & ";"
    That's assuming it's a 2 column value list.
    However if so, I think your semicolons are wrongly placed as there isn't one at the end of the 'list'
    Code:
    vol_my_worked_hrs.RowSource = vol_my_worked_hrs.RowSource & ";" & MyText1 & ";" & MyText2
    Of course if it's based on a table or query., that won't work at all
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    However if so, I think your semicolons are wrongly placed as there isn't one at the end of the 'list'
    I assumed that one was already there - and that's why I said probably.
    It's enough of a hint for the OP to figure it out...

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    And more than I originally intended to provide ....
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  7. #7
    ijared is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    19
    I removed the & ";" & MyText1 & ";" & MyText2. Nothing happened.

  8. #8
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Quote Originally Posted by ijared View Post
    I removed the & ";" & MyText1 & ";" & MyText2. Nothing happened.
    Why did you remove that? And what does nothing happened mean?

    Code:
    vol_my_worked_hrs.RowSource = vol_my_worked_hrs.RowSource & ";" & MyText1 & ";" & MyText2
    I just tested this and it worked for me!

    You need the following for that code to work
    a) listbox with row source = Value List
    b) 2 columns
    c) property 'Allow Value List Edits' set to Yes
    d) listbox name is 'vol_my_worked_hrs'

    Here's some alternative code that should also work

    Code:
       Me.vol_my_worked_hrs.AddItem MyText1 & ";" & MyText2
    If you are still stuck, there lots of hits for this topic on Google. For example:
    http://etutorials.org/Microsoft+Prod...+or+Combo+Box/
    https://msdn.microsoft.com/en-us/vba...-method-access

    Good luck
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  9. #9
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    if its a value list you can use
    Code:
    me.vol_my_worked_hrs.AddItem me.MyText1
    me.vol_my_worked_hrs.AddItem me.MyText2

  10. #10
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    It should be noted that unless the Form has been opened in Design View, the additional items will only be added for the duration that the Form is open. When the Form is closed and then reopened, the new items will no longer be there.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  11. #11
    ijared is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    19
    Quote Originally Posted by ridders52 View Post
    Why did you remove that? And what does nothing happened mean?

    Code:
    vol_my_worked_hrs.RowSource = vol_my_worked_hrs.RowSource & ";" & MyText1 & ";" & MyText2
    I just tested this and it worked for me!

    You need the following for that code to work
    a) listbox with row source = Value List
    b) 2 columns
    c) property 'Allow Value List Edits' set to Yes
    d) listbox name is 'vol_my_worked_hrs'

    Here's some alternative code that should also work

    Code:
       Me.vol_my_worked_hrs.AddItem MyText1 & ";" & MyText2
    If you are still stuck, there lots of hits for this topic on Google. For example:
    http://etutorials.org/Microsoft+Prod...+or+Combo+Box/
    https://msdn.microsoft.com/en-us/vba...-method-access

    Good luck
    followed the links listed here. The listbox is still empty.
    I

  12. #12
    ijared is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    19
    Quote Originally Posted by moke123 View Post
    if its a value list you can use
    Code:
    me.vol_my_worked_hrs.AddItem me.MyText1
    me.vol_my_worked_hrs.AddItem me.MyText2
    The listbox is still empty

  13. #13
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    This should help you see what's going on and whether you need the additional ";" before MyText1
    Code:
    Private Sub Addtolist_Click()
       Dim NewList as string
        
    msgbox "MyText1=" & myText1 & vbcrlf _
        & "MyText2=" & myText2 & vbcrlf _
        & "vol_my_worked_hrs.RowSource=" & vol_my_worked_hrs.RowSource
    NewList = vol_my_worked_hrs.RowSource & MyText1 & "," & MyText2 & ";"     
    msgbox "NewList=" & NewList
    vol_my_worked_hrs.RowSource = NewList
    End Sub

  14. #14
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    What exactly is it you are trying to do?
    Is the listbox query based or a value list?
    do you have your column counts and column widths set correctly?

    show the code for what you have tried.

  15. #15
    ijared is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    19
    Quote Originally Posted by moke123 View Post
    What exactly is it you are trying to do?
    Is the listbox query based or a value list?
    do you have your column counts and column widths set correctly?

    show the code for what you have tried.
    This is the data I have and nothing is added when I click Addtolist and don't understand why? Any help?

    Private Sub Addtolist_Click()
    vol_my_worked_hrs.RowSource = vol_my_worked_hrs.RowSource & MyText1 & MyText2 & ";"
    End Sub

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 01-02-2018, 10:56 AM
  2. Replies: 1
    Last Post: 09-11-2012, 11:49 PM
  3. Replies: 1
    Last Post: 09-10-2012, 11:21 PM
  4. projects database save listbox selections
    By taya621 in forum Access
    Replies: 33
    Last Post: 01-21-2011, 10:56 AM
  5. Replies: 1
    Last Post: 10-20-2009, 02:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums