Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List Box Problem

Status
Not open for further replies.

icupat

Technical User
Aug 6, 2002
25
CA
Ok. I have a list box that's populated with filenames. Anyways, it's a value list that I'm using. However when I close the form and then restart it, it only remembers the value of the item in the list box that was selected, it doesn't remember all the other values in the list box... is there a way to fix this?

Thanks.
 
I was putting the filename values in as rowsource btw, if that helps.
 
Hi,
Are you assigning these filenames at runtime or in the design view?

If it is at runtime, you could try to load the list at form open or store the list in some table and use that to populate the list.

At design time, I don't see any problems. Set the RowSourceType property to "Value List" and put in the filenames in the RowSource property as given below:

RowSource=filename1;filename2;filename3 etc. Hope it helps.

Let me know what happens.
With regards,
PGK
 
Rowsource type IS already set to "value list" and the filenames are brought in at run time through an api browser, that brings in the filenames in the windows explorer multi-select style that looks like this:

c:\path\%"filename1"%"filename2"

I then have a algorithm that seperates the filenames into the

rowsource=filename1;filename2;etc.

So I don't think that's the problem (the getting it in). Just seems to only store the selected value in the table for some reason. No clue why this would happen.

Also another question, text boxs are limited to 255 characters, does this mean the ROW SOURCE is limited to that same number of characters???

Thanks,
Patrick
 
Perhaps you can try the code yourself.

You'll neeed:
A list box called "mylistbox" set to "value list"
A command button called "browsefile"
A text box calle "directory"
A label called "myhyperlink"
A image box called "imageframe2"
A check box called "addcheck"

You can disable the cose for the imageframe and "addcheck" pretty easily I suppose though...

Just past this all onto the form code and it should work..
Thanks,

<code>


Private Declare Function GetOpenFileName Lib &quot;comdlg32.dll&quot; Alias &quot;GetOpenFileNameA&quot; (pOpenfilename As OPENFILENAME) As Long

Private Type OPENFILENAME
lStructSize As Long
hWndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrfile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Sub browsefile_Click()

Const OFN_ALLOWMULTISELECT = &H200&
Const OFN_EXPLORER = &H80000
Dim filenames$(), str

Dim OFName As OPENFILENAME
OFName.lStructSize = Len(OFName)
'Set the parent window
OFName.hWndOwner = Me.hwnd
'Set the application's instance
'OFName.hInstance = App.hInstance
'Select a filter
OFName.lpstrFilter = &quot;Jpegs (*.jpg)&quot; + chr$(0) + &quot;*.jpg&quot; + chr$(0) + &quot;All Files (*.*)&quot; + chr$(0) + &quot;*.*&quot; + chr$(0)
'create a buffer for the file
OFName.lpstrfile = space$(1054)
'set the maximum length of a returned file
OFName.nMaxFile = 1055
'Create a buffer for the file title
OFName.lpstrFileTitle = space$(1054)
'Set the maximum length of a returned file title
OFName.nMaxFileTitle = 1055

'Set the initial directory
If [directory] <> &quot;&quot; Then
OFName.lpstrInitialDir = [directory]
Else
OFName.lpstrInitialDir = &quot;\\Dataserver\&quot;
End If

'Set the title
OFName.lpstrTitle = &quot;Open File&quot;
'No flags
OFName.flags = OFN_ALLOWMULTISELECT Or OFN_EXPLORER

'Show the 'Open File'-dialog
If GetOpenFileName(OFName) Then

If [Check25] = -1 Then
mylistbox.RowSource = mylistbox.RowSource
Else
mylistbox.RowSource = &quot;&quot;
End If

z = 1
For i = 1 To Len(trim$(OFName.lpstrfile))
i = InStr(z, trim$(OFName.lpstrfile), chr(0))
If i = 0 Then Exit For
ReDim Preserve filenames(y)
filenames(y) = Mid(trim$(OFName.lpstrfile), z, i - z)
z = i + 1
y = y + 1
Next

If y = 2 Then
str = filenames(0)
w = 0
For z = 1 To Len(str)

chars = Right(str, z)

If InStr(chars, &quot;\&quot;) > 0 Then
Exit For
End If

w = w + 1

Next z
flname = Right(str, w)
direcname = left(str, Len(str) - w)

Me![directory] = direcname & &quot;\&quot;
mylistbox.RowSource = flname & &quot;;&quot;
Else
For i = 0 To y - 2
If i = 0 Then
Me![directory] = filenames(0) & &quot;\&quot;
Else
mylistbox.RowSource = mylistbox.RowSource & filenames(i) & &quot;;&quot;
End If
Next i
End If

Else
MsgBox &quot;You Have Canceled Your Browsing&quot;
End If

End Sub

</code>
 
I think part of the problem is that I want the ROWSOURCE to be difference for each record. So maybe I should store the string with filenames in a &quot;in-visible&quot; text box and just have the an form_onload() event that sends the names into the list box?? I think that may be the best solution.. what do you think?

I guess I'm wondering if there's a way to have difference rowsource for a list box for each different record..

Thanks,
Patrick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top