Opening next form in series based on lookup table

G

Guest

Hello,

I have some code (see below) which simply opens the next form in a series
based on a lookup table that contains all forms in the database and their
assigned number. I am executing the code behind a Command Butoon and have an
'OnCLick' [Event Procedure]. When I click the button, I get the error, 'Type
Mismatch'. There's not a whole lot of code and the name of the Lookup Table
is correct, what might be the reason I get a 'Type Mismatch' error message?
(Code below):

Private Sub BeginSeries_Click()

On Error GoTo Err_BeginSeries_Click
Dim strSQL As String, strName As String, rst As Recordset, dbs As Database

Set dbs = CurrentDb
strSQL = "SELECT * FROM [LU_Forms] WHERE [FormOrder] = 2"
Set rst = dbs.OpenRecordset(strSQL)

DoCmd.OpenForm rst![FormName], , , , acAdd

Exit_BeginSeries_Click:
Exit Sub

Err_BeginSeries_Click:
MsgBox Err.Description
Resume Exit_BeginSeries_Click

End Sub
 
D

Dan Artuso

Hi,
Try declaring your recordset as:
Dim rst As DAO.Recordset

So Access knows you want a DAO and not an ADO recordset.
 
G

Guest

That was it, thank you! Is this an old vs. new thing in Access? Because I
got this code from an Access97 database.

Thanks again, Patrick

Dan Artuso said:
Hi,
Try declaring your recordset as:
Dim rst As DAO.Recordset

So Access knows you want a DAO and not an ADO recordset.

--
HTH
Dan Artuso, Access MVP


Pat Dools said:
Hello,

I have some code (see below) which simply opens the next form in a series
based on a lookup table that contains all forms in the database and their
assigned number. I am executing the code behind a Command Butoon and have an
'OnCLick' [Event Procedure]. When I click the button, I get the error, 'Type
Mismatch'. There's not a whole lot of code and the name of the Lookup Table
is correct, what might be the reason I get a 'Type Mismatch' error message?
(Code below):

Private Sub BeginSeries_Click()

On Error GoTo Err_BeginSeries_Click
Dim strSQL As String, strName As String, rst As Recordset, dbs As Database

Set dbs = CurrentDb
strSQL = "SELECT * FROM [LU_Forms] WHERE [FormOrder] = 2"
Set rst = dbs.OpenRecordset(strSQL)

DoCmd.OpenForm rst![FormName], , , , acAdd

Exit_BeginSeries_Click:
Exit Sub

Err_BeginSeries_Click:
MsgBox Err.Description
Resume Exit_BeginSeries_Click

End Sub
 
D

Dan Artuso

Yes. In 97 the default reference was DAO. Now it's ADO.
They are two different data access libraries that both have a recordset object.

--
HTH
Dan Artuso, Access MVP


Pat Dools said:
That was it, thank you! Is this an old vs. new thing in Access? Because I
got this code from an Access97 database.

Thanks again, Patrick

Dan Artuso said:
Hi,
Try declaring your recordset as:
Dim rst As DAO.Recordset

So Access knows you want a DAO and not an ADO recordset.

--
HTH
Dan Artuso, Access MVP


Pat Dools said:
Hello,

I have some code (see below) which simply opens the next form in a series
based on a lookup table that contains all forms in the database and their
assigned number. I am executing the code behind a Command Butoon and have an
'OnCLick' [Event Procedure]. When I click the button, I get the error, 'Type
Mismatch'. There's not a whole lot of code and the name of the Lookup Table
is correct, what might be the reason I get a 'Type Mismatch' error message?
(Code below):

Private Sub BeginSeries_Click()

On Error GoTo Err_BeginSeries_Click
Dim strSQL As String, strName As String, rst As Recordset, dbs As Database

Set dbs = CurrentDb
strSQL = "SELECT * FROM [LU_Forms] WHERE [FormOrder] = 2"
Set rst = dbs.OpenRecordset(strSQL)

DoCmd.OpenForm rst![FormName], , , , acAdd

Exit_BeginSeries_Click:
Exit Sub

Err_BeginSeries_Click:
MsgBox Err.Description
Resume Exit_BeginSeries_Click

End Sub
 

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