Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    May 2002
    Location
    Dubai, UAE, United Arab Emirates
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Variable Definition (Access 2003)

    G'day All

    When I declare some variables like this:

    Dim UpTo, Total, LineNum as Long

    And then later use these to call a procedure:

    StatusChange("Processing Pairings", False, UpTo, Total, "Processing @ of @")

    I get an error message regarding inappropriate defining of data types in assocaition with the ByRef statement in my procedure definition:

    Sub StatusChange(Optional ByVal TextIn As Variant, Optional OKButton As Boolean, Optional UpTo As Long, Optional Total As Long, Optional ProgText As String)

    When I change the dim area of the calling procedure:

    Dim UpTo As Long
    Dim Total As Long
    Dim LineCount As Long

    The error goes away. So why can't you define a number of variables, separating them with comma's with a single data type?

    Regards Ken

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Variable Definition (Access 2003)

    This is the way Visual Basic works; it is different from for instance Pascal. If you omit the type in a declaration, a variable automatically becomes a Variant. You must declare the type for each variable separately if you want them to be something else than Variant. In

    Dim UpTo, Total, LineNum as Long

    UpTo and Total will be Variants since their type is not declared explicitly, only LineNum will be a Long. If you would keep the declarations on one line, use

    Dim UpTo As Long, Total As Long, LineNum as Long

    Again, you and I may regret this, but VBA has always been like that.

  3. #3
    2 Star Lounger
    Join Date
    May 2002
    Location
    Dubai, UAE, United Arab Emirates
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Variable Definition (Access 2003)

    Thanks - should've realised it'd be something like that.

Posting Permissions

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