User Defined Type

D

Dan @BCBS

My goal is to link two forms with a command button and learn how to define a
type.
Could you please help me define two new types (Database and Recordset)
This is my code.

Sub cmdProv_Click()
On Error GoTo Err_cmdProv_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim dbcurrent As Database
Dim rstemp As Recordset

If IsNull([ICNNO]) Then
MsgBox "Please enter the ICNSR # before proceeding."
Exit Sub
Else
'Check to see if a record already exists
Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from [t_PROV] where
[ICNSR] = " & "'" & Me.[ICNSR] & "'" & ";")
stDocName = "f_PROV"

If rstemp.RecordCount > 0 Then 'Open Record
stLinkCriteria = "[icnsr]=" & "'" & Me.[ICNSR] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else 'Create a new record
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!f_PROV.DataEntry = True
End If
Forms!f_PROV.ICNNO = Me.ICNSR
End If
 
D

Douglas J Steele

Database and Recordset are already objects in the Access.

I doubt very much that you're having a problem with Recordset not being
defined (although you may not be getting the correct one).

If it's complaining that Database is an unknown user type, that's because
you don't have a reference set to DAO. (By default, Access 2000 and Access
2002 only have a reference to ADO, not DAO).

While in the VB Editor, select Tools | References from the menu. Scroll
through the list of
 
D

Douglas J Steele

Oops, hit enter too soon.

Database and Recordset are already objects in the Access.

I doubt very much that you're having a problem with Recordset not being
defined (although you may not be getting the correct one).

If it's complaining that Database is an unknown user type, that's because
you don't have a reference set to DAO. (By default, Access 2000 and Access
2002 only have a reference to ADO, not DAO).

While in the VB Editor, select Tools | References from the menu. Scroll
through the list of available references until you find the Microsoft DAO
3.6 Object Library. Select it and close the dialog.

Since Recordset is an object in more than one object model, you'll need to
disambiguate:

Dim rstemp As DAO.Recordset

While not essential, you might also use

Dim dbcurrent As DAO.Database
 

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

Top