compile error

N

Nick T

Hi,
I have some code behind cmd button, however i keep getting a compile error
saying "User-Defined type not defined"

What does this mean & how can i resolve this??

My code if necessary is:


Private Sub Command31_Click()

Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("LogQuery", dbOpenDynaset)
With rst
.FindFirst "[ProductDescription] = " & Me.ProductDescription

If .NoMatch Then
MsgBox "blar blar blar"
DoCmd.Close
Else
Me.TotalWeight = ![Sum Of Weight(kg)]

End If

.Close
End With
Set rst = Nothing
End Sub

Any suggestions welcome.
Many thanks
 
N

Nick T

Hi Hans,
Im using access 2002.

Humm, references, iv had a look but im 'self taught' at this so havnt dabled
in references before. Perhaps you could explain a little more?

Thanks for your help.
 
N

Nick T

All sorted!

A bit of playing using your tip has sorted the problem!
Many thanks for your help!
 
H

Hans Up

Nick said:
Hi Hans,
Im using access 2002.

Humm, references, iv had a look but im 'self taught' at this so havnt dabled
in references before. Perhaps you could explain a little more?

OK. It sounds like you were able to follow the menu path, and get to
the references dialog (Right?)

References are what VBA uses to find the appropriate code when you refer
to an object, constant, whatever. For example, in your code you had:

Dim rst As DAO.Recordset

In order for that to work, you need a reference to the DAO type library
.... so that VBA knows where to find that Recordset "thing". If you
don't have a reference set (marked with a check in the References
dialog) for DAO, your code will cause an error at compile time. In some
situations, you could have a reference checked, but the type library
(the actual file on your hard drive) is not present. That can happen,
for example, if you had a reference set for the Excel 11 type library,
but later upgraded to Excel 12. You would still have an Excel type
library on your system, just not the one which your reference is looking
for. In that situation, you need to remove the checkmark from the
missing reference and place a checkmark next to the version which you
have on your system.

Have another look at the references dialog and see if it makes more
sense to you now. Tell about any which look suspicious. I'm sure we
can Google up some code to enumurate your references and their status if
needed. But I need to break away for a while just now. I'll be sure to
check back later to see how you're getting on.

Hans
 
H

Hans Up

Nick said:
All sorted!

A bit of playing using your tip has sorted the problem!
Many thanks for your help!

Hey, Nick! That's good news. I just now sent off a reply to your
earlier message. That was my rather pitiful attempt at a short course
in references. It's probably good you didn't need it after all. :)

Cheers,
Hans
 
J

John Spencer

And which line does it highlight when it gives you the message. If I
were going to bet I would bet
Dim rst as DAO.Recordset
Which usually means that you have not selected the DAO Library resource.

In the VBA window
From menu. Tools: References
Select Microsoft DAO 3.6 Object Library

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top