Re: Sub routine syntax errors



On Sun, 12 Aug 2007 19:15:14 -0400, "Len Robichaud"
<len.robichaud@xxxxxxxxxxxxxx> wrote:

Where are you putting this code? It should be in the class module of the
Form. If you are trying to run this from another module it will fail.
If you are running this from another module you need to refer to the control
as Forms!Form1!ctla.etc...
The code is in project module. You are correct, and yes I have been.


"Chuck" <libbeyc@xxxxxxxxxxxxxx> wrote in message
news:r02vb3p98ntkp2ek2agugeq1gr01cepoe8@xxxxxxxxxx
On Sun, 12 Aug 2007 16:43:00 -0400, "Len Robichaud"
<len.robichaud@xxxxxxxxxxxxxx> wrote:

Try this:
Dim i as Integer

For i = 0 To Me.ctla.ListCount - 1
If Me.ctla.Selected(i) = True Then
Me.Text1 = Me.ctla.ItemData(varItem)
End If
Next i
Debug says improper use of 'Me.' so I've been replacing all the 'Me.' with
'Form1.'.

Me.ctla.Selected(i) does = true.
varItem = row count -1 of item selected. (zero base)
however
Me.ctla.ItemData(varItem) = null
The list has a single column of data (text) that it gets from a table.
I set the table property of 'indexed' to Yes (No Duplicates). It didn't
help.
I can scroll the list box up and down and select one or more items. The
items
remain selected until the form is closed.

Chuck


"Chuck" <libbeyc@xxxxxxxxxxxxxx> wrote in message
news:aj8ub39tuur49b6t42d0sr1j91g07jknig@xxxxxxxxxx
On Sat, 11 Aug 2007 23:45:20 -0400, "Len Robichaud"
<len.robichaud@xxxxxxxxxxxxxx> wrote:

Try this...
First create a Command Button named btnRunThis on the Form that contains
ctla and text1.
Go to the button's properties and in the OnClick event invoke Code Builder
and paste in the code below
Air Code Warning...
***********************
Sub btnRunThis_OnClick()
On Error goto btnRunThis_OnClick_Error
Dim db as CurrentDB
Dim varItem as Variable
Dim strSql as String

'Delete all Records from WorkingTable
strSql = "Delete * FROM WorkingTable;"
db.execute strSql

'Me refers to the form that contains this code
For Each varItem In Me.ctla.ItemsSelected
Me.Text1 = Me.ctla.ItemData(varItem)

DoCmd.RunMacro "AppendData"
Next varItm

Resume btnRunThis_OnClick_Exit:
Exit sub

btnRunThis_OnClick_Error:
msgbox Err.Number & " " & Err.Description
Resume btnRunThis_OnClick_Exit

End Sub
**********************************

Good Luck

Len Robichaud

Open the Form1.
Select 4 items from the ctla list box. (list box only has one column)
Leaving the form open.
Open the sub and step through the code.
The program properly runs thru the for next loop four times.
Each time the loop reaches "ctla.ItemData(varItem)" holding the mouse
cursor
over the code shows "ctla.ItemData(varItem) = null"
If varItem is examined it shows 0, 1, 2, 3 which is correct for the 4 items
selected.

If ctla.ItemData(varItem) is replaced with ctla.ItemData(2), the code fails
to
run.

What is happening to ItemData?

Chuck


.