Results 1 to 3 of 3
  1. #1
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    6 Feet Under

    How To Know What Type A Variable Should Be

    I have inherited a database from someone, and they did not have
    Option Explicit
    at the top of the editor. I have since added it and have declared all the missing variables, but I have a question about one. I think this one should be declared as String - but wanted to ask. It is importing an Excel File into an access table should selectedFile be declared as String? Is there a way to tell what the variable type should be from the VBE?

    Function Import()
    Dim f As Object
    Dim I As Integer
    Dim ir As String: ir = "A1: Z100"
    Set f = Application.FileDialog(3)
    With f
      .AllowMultiSelect = False
      .Title = "Pick File"
      .Filters.Add "Excel Files", "*.xlsx"
      If .Show = True Then
        For I = 1 To f.SelectedItems.Count
          selectedfile = f.SelectedItems(i)
      '....more code here
    End Function
    What should selectedfile be declared as?

  2. #2
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Anchorage, Alaska, USA
    Your code is very similar to the code I use to pick files. In my code, the Path and file name is returned as a string.

    So I would delcare "selectedFile" as a string

    Dim selectedFile As String
    "Veni, Vidi, Velcro"
    (I came; I saw; I stuck around.)

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Ontario, Canada
    f is the file dialog object.
    .selecteditems is a collection, which is an object.
    .selectedItems(i) is one specific member of that collection, which is the path to the file, which AFAIK is text.
    However, list item variables are always(?) declared as variants.

    I would guess that String would be what you want because the collection list is text based.

    Sigghhh, you weren't there when I started...
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    "Everyone has a photographic memory; some just don't have film." Steven Wright

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 12-31-2018, 07:30 PM
  2. Defining Variables, Which Variable Type and When?
    By nick404 in forum Programming
    Replies: 4
    Last Post: 07-07-2015, 01:13 PM
  3. Replies: 5
    Last Post: 10-27-2014, 10:33 PM
  4. data type variable constants
    By markjkubicki in forum Programming
    Replies: 2
    Last Post: 06-20-2012, 09:57 PM
  5. variable uses automation type not supported
    By eerkut in forum Programming
    Replies: 4
    Last Post: 02-15-2012, 03:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Other Forums: Microsoft Office Forums - Senior Forums