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

Help with object type please in Access form 1

Status
Not open for further replies.

mike777

Programmer
Jun 3, 2000
387
US
I am trying the following code:
Code:
Function test()
Dim a As Field
Set a = Forms!calculator!tb_rate
MsgBox a
End Function
and I get the following error message:
Run-time error 13
Type Mismatch

What am I doing wrong?
If I dim like
Code:
Dim a
it works, but I think I should be using an object type, no?
Thanks for your help.
michael.kemp@gs.com
 
This example is based on you call the function from the same form you want. But you could also accomplish the same thing by using the Textbox name that the Field is the ControlSource of. (i.e. txt1 uses tb_rate as its ControlSource)

MsgBox txt1

Function Test()
Set a = Me.RecordsetClone("tb_rate")
Me.RecordsetClone.Bookmark = Me.Bookmark
MsgBox a
End Function


PaulF
 
When you Dim a As Field, the type of a is Field (an object). But the first parameter of MsgBox must be a string, and there's no defined way to convert an object to a string.

What you want is the contents of the field, not the Field object. Try this:
MsgBox a.Value

It works when you Dim a without specifying a type, because then the type is Variant. When you use a Variant in the MsgBox statement, VBA searches for a way to convert it to a string. If the argument is an object, one of the things VBA tries is the default property of the object, if it has one. Guess what the default property of a Field object is--right! It's Value. Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top