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

type mismatch error

Status
Not open for further replies.

striker73

MIS
Jun 7, 2001
376
US
I am receiving a type mismatch error in my code and I can't figure out what's going on. Any ideas? Thanks! The offending code follows:

Private Sub Form_Load()
Dim StartingForm as Form
Set StartingForm = Forms!frmClientInfo.Form
DisplayFunction (StartingForm) <--ERROR ON THIS LINE

End Sub


Private Function DisplayFunction (FormName as Form)
FormName.txtMyTextBox = &quot;yay!&quot;
End Function
 
Couple of things off top of my head...
I would be careful with using possible reserved words as variable names (FormName?). Next, I thought a function call requires an &quot;=&quot;...
lnResponse=DisplayFunction (StartingForm)

htwh... Steve Medvid
&quot;IT Consultant & Web Master&quot;
web page under development...
 
Dear striker,

in

DisplayFunction (StartingForm) <--ERROR ON THIS LINE

remove the () like this

DisplayFunction StartingForm

>> I forgot the english word for () maybe brackets??<<

by setting the brackets you tell the function to the argument by value. But Access is not able to copy the object into a new object. And even if, it would not be what you want to achieve.

kind regards Astrid
 
Dear Striker ,

just for completeness:

if you have it like

lnResponse=DisplayFunction (StartingForm)

you have to put the brackets , as otherwise VB(A) / Access will not compile. please don't ask ME why it is so weared.


in addition to this you should only declare a function if you want to have given a value back.
If you define a function , allways provide the type of the return value.
like this:


Private Function DisplayFunction (FormName as Form) as boolean ' or whatever type
FormName.txtMyTextBox = &quot;yay!&quot;

displayfunction = true 'assign the value to the functionsname
End Function

if you do not define the type of the return value , it is define by default as Variant which is allways the largest possible Datatype. (Could be a geeky way to make your compiled file look big ;-) )


kind regards Astrid



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top