Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2006
    Posts
    12

    Question Unanswered: Using a combo box as an array item in VBA

    I'm having a brainfade moment. I have a collection of combo boxes that I want to use in a loop to say that if the combo box is not empty then run the function then move onto the next combo box. I can't for the life of me remember how to do it.

    Here's my code so far - I know this is wrong, but can't remember or find the right code.

    All help will be much appreciated.

    Sub cmd_Import_Files_Click()

    Dim strTable As String
    Dim strFolderName As String
    Dim strFileName As String
    Dim strSheet As String
    Dim str_sheet As String
    Dim strPath As String
    Dim j As Integer
    Dim i As Integer

    i = 2

    For j = 1 To i

    str_sheet = "Me.cbx_SheetNames" & j & ".Value"

    If str_sheet <> "" Then

    ' strTable = Me.txt_ImportTableName(j).Value
    ' strFolderName = Me.txt_FolderPath(j).Value
    ' strFileName = Me.txt_FileName(j).Value
    ' strSheet = Me.cbx_SheetNames(j).Value
    ' strPath = strFolderName & "\" & strFileName

    'Debug.Print strTable
    'Debug.Print strFolderName
    'Debug.Print strFileName
    'Debug.Print strSheet
    'Debug.Print strPath

    Application.Run ImportExcel(strTable, strPath, strSheet)
    End If

    Next j

    End Sub

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    You mean control arrays? Not in Access - you'll need to uniquify their names.
    I think you want:
    Code:
     str_sheet = me.Controls("cbx_SheetNames" & j).Value

  3. #3
    Join Date
    Sep 2006
    Posts
    12

    Talking

    Quote Originally Posted by pootle flump
    You mean control arrays? Not in Access - you'll need to uniquify their names.
    I think you want:
    Code:
     str_sheet = me.Controls("cbx_SheetNames" & j).Value
    Thanks you so much - that seems to have done the trick! You are a star!

Posting Permissions

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