Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with User Defined Types (UDT) as a record

Status
Not open for further replies.

brimes2

Programmer
Jan 19, 2009
8
US
I'm having trouble in Access trying to work with a UDT as a whole/record. I seem to recall that this is a limitation in Access that is not in VB6.

Specifically, I'd like to be able to initialize the record with spaces and be able to write it to disk as a whole with the Write or Print statement.

Is there a workaround for this? Maybe an API call?

Thanks,
Brooks

Option Compare Database
Option Explicit

Type CustomerRecord
Customername As String * 50
Address1 As String * 50
' many more fields
End Type

Sub Main()
Dim custrec As CustomerRecord

custrec = Space(100) ' gives a compile error
LSet custrec = Space(100) ' gives error 13

custrec.Customername = "anyname"
custrec.Address1 = "anystreet"

MsgBox custrec ' gives a compile error

End Sub
 
When you;

Dim custrec As CustomerRecord

custrrec is already initialised. Customername and Address1 will contain 50 ascii zeros (chr$(0)) each.

If you want to fill the fields with spaces you will have to do that explicitly with;

custrec.CustomerName = space$(50)
custrec.Address1 = space$(50)

I wonder if you really need to fill the fields with spaces before filling them with 'real' values?

As for MsgBox; you'll have to code that explicitly for each field too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top