Results 1 to 7 of 7

Thread: Code Question

  1. #1
    Join Date
    Sep 2006
    Posts
    162

    Unanswered: Code Question

    I was using this code I found on the forums to prompt user for location of a file. When it runs i get this error.

    Compile error:
    User-defined type not defined

    on the Dim fd As FileDialog

    Not sure if its cause this is old code and theres a new way to do it.

    TIA

    PHP Code:
    Private Sub Command2_Click()
    'Declare a variable as a FileDialog object.
    Dim fd As FileDialog
    Dim strFiles As String, strInitialView As String

    strInitialView = "C:\"

    Set fd = Application.FileDialog(msoFileDialogFilePicker)

    Dim vrtSelectedItem As Variant

    With fd
    .Filters.Add "Excel Files", "*.xls; *.xl*", 1
    .InitialFileName = strInitialView
    If .Show = -1 Then

    For Each vrtSelectedItem In .SelectedItems

    strFiles = strFiles & vrtSelectedItem & ";"

    Next vrtSelectedItem
    Else
    Set fd = Nothing
    Exit Sub
    End If
    End With
    strFiles = Left(strFiles, Len(strFiles) - 1)
    Me.lboxSelFiles.RowSourceType = "Value List"
    Me.lboxSelFiles.RowSource = strFiles

    Set fd = Nothing
    End Sub 

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    that message would indiocate to me you are missing a reference to the relevant library
    i forget which one that uses but in the VBA code window check to see what windows librries aree checked and available
    it may be windows common controls...
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Sep 2006
    Posts
    162
    rgr, i'll try and figure out which library it is.

    thanks

  4. #4
    Join Date
    Sep 2006
    Posts
    162
    Ok found it, but now i'm getting this error.

    Compile error
    Method or data member not found.

    on line
    Me.lboxSelFiles.RowSourceType = "Value List"


    Sorry, but I'm new to VBA, learning as I go

  5. #5
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    lboxSelFiles should be a ListBox, shouldn't it?

  6. #6
    Join Date
    Sep 2006
    Posts
    162
    Can you explain a little more, this isn't my code.

    I'm just now learning it.

  7. #7
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    I think the lBoxSelFiles is a ListBox on your Form. You can drop Me.lboxSelFiles.RowSourceType = "Value List" and adjust it in the properties window of the listbox, just adjust it to "Value List"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •