Results 1 to 3 of 3
  1. #1

    user-defined type of variable

    (Access97 VBA)
    I need to read and write external file(s) whose records are file header,batch header, detail record(s) batch trailer, file trailer all of which have different formats. So ... I set up a handful of types like ...

    Option Compare Database
    Option Explicit
    Private Type FileHeader
    fh1234 As String * 4
    fhDest As String * 9
    fhComID As String * 10
    . . .
    end type

    with the expectation that I could say
    . . .
    Dim FH as FileHeader
    mycursor = Input(96, #1) ' Get first record
    FH = mycursor

    and have the individual fields available for manipulation.

    What I got, of course was "Type Mismatch error"

    In general, I'm looking something which can be looked at in one piece and/or by named parts.

    Any answers or suggestions as to where to look gratefully accepted.

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Sacramento, California, USA
    Thanked 1 Time in 1 Post

    Re: user-defined type of variable

    It looks like you're trying to read the first 96 characters of a text file directly from it into a custom data type, so I'm not surprised you're getting errors. Input always returns a string of the specified length, which doesn't match your data type structure.

    There are two ways of populating a custom data type: 1) explicitly set one or more of it's members in code, or 2) pass it a paramarray that matches the structure of the data type. Access has no idea of what to do with the 96-character string you're trying to stuff into that data type unless you do the work to parse the pieces out first.

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Winnipeg, Canada
    Thanked 0 Times in 0 Posts

    Re: user-defined type of variable

    It seems to me from what your are describing that the variable 'mycursor' will contain a string that needs to
    be cut into pieces. The individual pieces would be assigned to the fields in the FH object.

    Copy this bit of code to a module and then run Mytest from the Immediate window:

    Sub mytest()
    Dim FH As FileHeader
    mycursor = "abcdefghijklmnopqrstuvwxyz"

    FH.fh1234 = Left$(mycursor, 4)
    FH.fhDest = Mid$(mycursor, 5, 9)
    FH.fhComID = Mid$(mycursor, 14, 10)

    Debug.Print FH.fh1234
    Debug.Print FH.fhDest
    Debug.Print FH.fhComID

    End Sub

    Worked for me in VB5.

Posting Permissions

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