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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing user defined types.

Status
Not open for further replies.

Dustman

Programmer
May 7, 2001
320
US
I have created a public type called specimen in a standard module. I use the information in several forms so I originally created it like this to keep from having to pass all the variables around. I am now trying to rework how the DB is designed. Instead of making a global specimen, I need to make one and pass it from function to function until I'm done with it. Doing this globally is dangerous because I might not have the newest values loaded.

My problem is passing the variable. Everytime I instantiate the variable and try to pass it, I get an error saying only public object types can be passed. If its declaired Public Type in my public module.. is it not public?

This is in my public module:
Code:
Public Type Specimen
    Dim patientNumber As Integer
    Dim year As String
    Dim sType As String
    Dim TestType As String
    Dim test As String
    Dim number As String
    Dim untouched As String
    Dim formated As String
    Dim other As String
    Dim valid As Boolean
End Type

I instantiate the variable using a function..
Code:
Public Function ValidSpecimenCode(Code As String) As Specimen
  dim spcCode as Specimen
  spcCode.untouched = Code
  'other code to format the code and fill vars..
  .......
  ValidSpecimenCode = spcCode
End Function
I use it like so..
Code:
dim spcCode as Specimen
spcCode = ValidSpecimenCode("01-0002-GB")

I'm not used to doing this with VB. Is this not possible?

Bonus Questions: Does VB treat types like java and c++ treats arrays and classes? Is the variable actually just a pointer? Would it be better to create a class called specimen? -Dustin
Rom 8:28
 
Friend only applies if I'm using a class module. It cannot be used in a standard module.

BTW, The code posted here works. I can create a variable using the ValidSpecimenCode(). I get an error when I try to take that value and send it to another function:
Code:
dim spcCode as Specimen
spcCode = ValidSpecimenCode("01-0002-GB")
spcCode.patientNumber = [Patient#]
EnterNewTest(spcCode)

I get the following error from them EnterNewTest procedure:
Compile error:
Only user-defined types defined in public object modules can be coerced to or from a variant or passed to late-bound functions

Code:
Public Sub EnterNewTest(spcCode As Specimen)
'This will determine the right form to load for the new test.
'It it called by the patient information form.

Select Case UCase(spcCode.TestType)
 Case "G"
   DoCmd.OpenForm "BuildReport", , , , acFormAdd, , spcCode
 Case "Z"
   DoCmd.OpenForm "BuildFishReport", , , , acFormAdd, , spcCode
 Case "U"
   DoCmd.OpenForm "BuildReport", , , , acFormAdd, , spcCode
 Case "Y"
   DoCmd.OpenForm "BuildReport", , , , acFormAdd, , spcCode
 Case Else
   MsgBox "No Case found"
End Select
End Sub
The error hightlights the procedure in yellow and then highlights the spcCode under Case "G" in blue. -Dustin
Rom 8:28
 
I think I've discovered my problem.. I'm trying to pass a variable using the openargs on the new form. OpenArgs are for strings only right? If so.. any suggestions other than a global variable that will allow me to send information to the forms load event? -Dustin
Rom 8:28
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top