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

    How To Know What Type A Variable Should Be

    I have inherited a database from someone, and they did not have
    Code:
    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?

    Code:
    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
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    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

    Code:
    Dim selectedFile As String

  3. #3
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    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.

    EDIT
    Sigghhh, you weren't there when I started...
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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