Okay, I am fairly good at the basics of VBA and Access but I learned it on my own. I never took a VB class or any other OO class. Therefore, sometimes the terminology stumps me.
I am trying to create a user-defined type:
Public Type Input_Header
RecType As String * 3
HeaderDate As String * 8
FileName As String * 44
End Type
I want to assign a variant variable to that type, i.e:
Dim strHeaderString As Input_Header
strHeaderString = varLine
When I try to run this, I get the error "Only user-defined types defined in public object modules can be coerced to or from a variant or passed to late-bound functions".
I have no idea was "public object modules" or "late-bound functions" means. Like I said, I have no OO training. So if anyone can explain this in simple terms I would appreciate it.
Just to give you an idea of what I am doing, here is my code (obviously there will be more. I just need to get this working before I move forward):
Public Sub ImportExtract()
On Error GoTo Err_ImportExtract
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fs, f, ts, s
Dim strLine As String
Dim varLine As Variant
strInputFile = "C:\My_Data\Extracts\extractBilling_121203.txt"
Set fs = CreateObject("Scripting.FileSystemObject"
Set f = fs.GetFile(strInputFile)
Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
Do While ts.AtEndOfStream <> True
varLine = ts.ReadLine
Select Case Left(varLine, 3)
Case "000"
Call imp_get_header(varLine)
..... (more case statements here)
End Select
Loop
Exit_ImportExtract:
Exit Sub
Err_ImportExtract:
Resume Exit_ImportExtract
End Sub
-----------------------------------------------------------
Public Sub imp_get_header(varLine As Variant)
On Error GoTo Err_imp_get_header
Dim strHeaderString As Input_Header
strHeaderString = varLine
MsgBox "Record Type = " & strHeaderString.RecType
MsgBox "Header Date = " & strHeaderString.HeaderDate
MsgBox "File Name = " & strHeaderString.FileName
Exit_imp_get_header:
Exit Sub
Err_imp_get_header:
Resume Exit_imp_get_header
End Sub
Thank you for your help.
Tammy
I am trying to create a user-defined type:
Public Type Input_Header
RecType As String * 3
HeaderDate As String * 8
FileName As String * 44
End Type
I want to assign a variant variable to that type, i.e:
Dim strHeaderString As Input_Header
strHeaderString = varLine
When I try to run this, I get the error "Only user-defined types defined in public object modules can be coerced to or from a variant or passed to late-bound functions".
I have no idea was "public object modules" or "late-bound functions" means. Like I said, I have no OO training. So if anyone can explain this in simple terms I would appreciate it.
Just to give you an idea of what I am doing, here is my code (obviously there will be more. I just need to get this working before I move forward):
Public Sub ImportExtract()
On Error GoTo Err_ImportExtract
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fs, f, ts, s
Dim strLine As String
Dim varLine As Variant
strInputFile = "C:\My_Data\Extracts\extractBilling_121203.txt"
Set fs = CreateObject("Scripting.FileSystemObject"
Set f = fs.GetFile(strInputFile)
Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
Do While ts.AtEndOfStream <> True
varLine = ts.ReadLine
Select Case Left(varLine, 3)
Case "000"
Call imp_get_header(varLine)
..... (more case statements here)
End Select
Loop
Exit_ImportExtract:
Exit Sub
Err_ImportExtract:
Resume Exit_ImportExtract
End Sub
-----------------------------------------------------------
Public Sub imp_get_header(varLine As Variant)
On Error GoTo Err_imp_get_header
Dim strHeaderString As Input_Header
strHeaderString = varLine
MsgBox "Record Type = " & strHeaderString.RecType
MsgBox "Header Date = " & strHeaderString.HeaderDate
MsgBox "File Name = " & strHeaderString.FileName
Exit_imp_get_header:
Exit Sub
Err_imp_get_header:
Resume Exit_imp_get_header
End Sub
Thank you for your help.
Tammy