Error opening database w/VBA

S

Samantha

I'm trying to write a query using codes, but I keep getting this message on
declaring my Database:
Compile error:
User-defined type not defined.

Here's what I have written:

Private Sub cboPOKey_AfterUpdate()
Dim D As Database
Dim rsInfo As Recordset
Dim strSQL As String

Set D = CurrentDb
PODetail.POUnitPrice, PODetail.QuantityRecived, "strSQL = "SELECT
PODetail.PODetail_PKey, PODetail.PONumber, PODetail.POLine FROM PODetail
WHERE"
strSQL = strSQL & "[PODetail.PODetail_PKey] = '" & Me!cboPOKey & "'"
Set rsInfo = D.Openrecordset(strSQL, DB_OPEN_DYNASET)
Me!tabInfo.Pages(1).SetFocus
Me!txtPOKey = rsInfo("PODetail_PKey")
Me!txtPONum = rsInfo("PONumber")
Me!txtPOLine = rsInfo("POLine")
rsInfo.Close

I checked with Access' internal help support and that's what the example
said to use. Have I missed anything? I've been testing this for the last 2
days! Can somebody help me? Thanks in advance.
 
D

David Kennedy

Hi Samantha,

Im not an expert on this but try:

Open the code window

On the Menu click Tools > References

Then Uncheck Microsoft ActiveX Data Objects 2.1 Library

and look for Microsoft DAO 3.6 Object Library in the list and check.

Hit Ok

Regards

David K
 
L

Lynn Trapp

Samantha,
David is correct that you need to set a reference to DAO 3.6. However, you
will also need to make a slight change to 2 lines in your code.

Dim D As DAO.Database
Dim rsInfo As DAO.Recordset
 
S

Samantha

Lynn and David,
I made the changes your suggested but it's now giving me a different VB
error message:
Run-time error '3464':
Data type mismatch in criteria expression.

The error is for the following expresssion:
Set rsInfo = D.OpenRecordset (strSQL, DB_OPEN_DYNASET)

I'm not sure what's wrong with the above statement?
Thanks for you help.

Samantha

Lynn Trapp said:
Samantha,
David is correct that you need to set a reference to DAO 3.6. However, you
will also need to make a slight change to 2 lines in your code.

Dim D As DAO.Database
Dim rsInfo As DAO.Recordset


--
Lynn Trapp
MS Access MVP
www.ltcomputerdesigns.com
Access Security: www.ltcomputerdesigns.com/Security.htm


Samantha said:
I'm trying to write a query using codes, but I keep getting this message on
declaring my Database:
Compile error:
User-defined type not defined.

Here's what I have written:

Private Sub cboPOKey_AfterUpdate()
Dim D As Database
Dim rsInfo As Recordset
Dim strSQL As String

Set D = CurrentDb
PODetail.POUnitPrice, PODetail.QuantityRecived, "strSQL = "SELECT
PODetail.PODetail_PKey, PODetail.PONumber, PODetail.POLine FROM PODetail
WHERE"
strSQL = strSQL & "[PODetail.PODetail_PKey] = '" & Me!cboPOKey & "'"
Set rsInfo = D.Openrecordset(strSQL, DB_OPEN_DYNASET)
Me!tabInfo.Pages(1).SetFocus
Me!txtPOKey = rsInfo("PODetail_PKey")
Me!txtPONum = rsInfo("PONumber")
Me!txtPOLine = rsInfo("POLine")
rsInfo.Close

I checked with Access' internal help support and that's what the example
said to use. Have I missed anything? I've been testing this for the last 2
days! Can somebody help me? Thanks in advance.
 
Top