UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Write All Items In A List Box To A Table., Access 2016    
 
   
alorenzini
post Dec 23 2017, 05:07 PM
Post#1



Posts: 791
Joined: 21-September 07
From: South Dakota


I am trying to write all the items in a listbox to a table. This is the code I have come with so far:



For each itm in me.lsteSubFolder.ItemSelected
rstSubFolder.AddNew
rstSubFolder!SubLevelOneKey = me.txtSubLevelOneKey
rstSubFolder!SubFolderName = Me.txtSubFolder01Label
rstSubFolder!CAbinetID = me.TxtCabinetID
rstSubFolder!SL1NextLevel = "No"
rstSubFolder.Update

Loop

I know this is not quite right because I am using ItemSelected but I want to write all items in the listbox to the table.
Go to the top of the page
 
GroverParkGeorge
post Dec 23 2017, 05:10 PM
Post#2


UA Admin
Posts: 33,794
Joined: 20-June 02
From: Newcastle, WA


Does the code compile? No errors?
Go to the top of the page
 
alorenzini
post Dec 23 2017, 05:15 PM
Post#3



Posts: 791
Joined: 21-September 07
From: South Dakota


Yes it does. But does not write anything to the table.
Go to the top of the page
 
GroverParkGeorge
post Dec 23 2017, 05:20 PM
Post#4


UA Admin
Posts: 33,794
Joined: 20-June 02
From: Newcastle, WA


Try this syntax instead:

CODE
With Me
    For Each varX In .lsteSubFolder.ItemsSelected

        rstSubFolder.AddNew
        rstSubFolder!SubLevelOneKey =  .lsteSubFolder.ItemData(varX)
        rstSubFolder!SubFolderName = Me.txtSubFolder01Label
        rstSubFolder!CAbinetID = me.TxtCabinetID
        rstSubFolder!SL1NextLevel = "No"
        rstSubFolder.Update
    Next varX
End With


Note that you need to use ItemsSelected, not ItemSelected.

Go to the top of the page
 
alorenzini
post Dec 23 2017, 05:48 PM
Post#5



Posts: 791
Joined: 21-September 07
From: South Dakota


THis is really close but the only problem is I have to select items and then click my cmdDone button. I just want to click the cmdDone and have it write all items in the list box automatically.
Go to the top of the page
 
GroverParkGeorge
post Dec 23 2017, 05:56 PM
Post#6


UA Admin
Posts: 33,794
Joined: 20-June 02
From: Newcastle, WA


"... have it write all items in the list box automatically." Oh, that's a different requirement then....

Add a preparatory loop that moves through all of the items in the listbox, selecting them all one at a time.

Then Loop it again with the suggested code to add them to the table.
Go to the top of the page
 
alorenzini
post Dec 23 2017, 06:56 PM
Post#7



Posts: 791
Joined: 21-September 07
From: South Dakota


OK Getting closer


For i = 0 To Me.lsteSubFolder.ListCount - 1

rstSubFolder.AddNew
rstSubFolder!SubLevelOneKey = Me.txtSubLevelOneKey
rstSubFolder!SubFolderName = Me.lsteSubFolder.ItemData(itm)
rstSubFolder!CAbinetID = Me.txtCabinetID
rstSubFolder!SL1NextLevel = "No"
rstSubFolder.Update

Next i


This almost works but not quite. If i put 3 items in the list box then its repeating the the first item in the listbox 3 times in the table, so instead of giving me APPLICANT, DATE, COMPANY it is writing APPLICANT,APPLICANT,APPLICANT in the table/
Go to the top of the page
 
GroverParkGeorge
post Dec 23 2017, 07:11 PM
Post#8


UA Admin
Posts: 33,794
Joined: 20-June 02
From: Newcastle, WA


Look at the code I posted.

Look at the code you came up with.

Do you see anywhere the code is actually looking at different rows in the listbox?

How about the value of the variable (itm)?

Me.lsteSubFolder.ItemData(itm)


When does it change?
Go to the top of the page
 
alorenzini
post Dec 23 2017, 07:19 PM
Post#9



Posts: 791
Joined: 21-September 07
From: South Dakota


OK. I got it. Thank you.

For i = 0 To Me.lsteSubFolder.ListCount - 1

rstSubFolder.AddNew
rstSubFolder!SubLevelOneKey = Format(Now(), "mmddyyhhmmss") & strCurrentUserName & "SUB"
rstSubFolder!SubFolderName = Me.lsteSubFolder.ItemData(i)
rstSubFolder!CAbinetID = Me.txtCabinetID
rstSubFolder!SL1NextLevel = "No"
rstSubFolder.Update

Next i
Go to the top of the page
 
GroverParkGeorge
post Dec 24 2017, 07:12 AM
Post#10


UA Admin
Posts: 33,794
Joined: 20-June 02
From: Newcastle, WA


Congratulations on solving the problem.

Continued success with your project.
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    23rd October 2018 - 06:36 AM