Error on Button Code

R

Ripper

I am using the following code to open a random for from a list of forms in tblFormList

Private Sub Command0_Click(

'Highest form numbe
Const lngcUpperBound =

'Lowest form numbe
Const lngcLowerBound =

Dim lngFormNumber As Lon
Dim strFormName As Strin

'Requires reference to Microsoft DAO 3.6 Object Library (or 3.51 forAccess 97)
Dim db As DAO.Databas
Dim rst As DAO.Recordse

'Generate a random number in the specified range. See 'Rnd Function' in the help file for details
Randomize Time
lngFormNumber = Int((lngcUpperBound - lngcLowerBound + 1) * Rnd + lngcLowerBound

'Open a recordset to get the form name corresponding to the random number
Set db = CurrentD
Set rst = db.OpenRecordse("SELECT FormName FROM tblFormList WHERE FormNumber = " & lngFormNumber
strFormName = rst.Fields("FormName"
rst.Clos

'Open the form
DoCmd.OpenForm strFormNam

I get an error of a user defined-type not defined when running the following lines
Dim db As DAO.Databas
Dim rst As DAO.Recordse

This is code I received on this newgroup, thanks to Brendan Reynolds for his help. Anyone have any idea how to fix the error I am running Access '02 on windows 2000

Thanks As Always
RIP
 
D

Dirk Goldgar

Ripper said:
I am using the following code to open a random for from a list of
forms in tblFormList.

Private Sub Command0_Click()

'Highest form number
Const lngcUpperBound = 6

'Lowest form number
Const lngcLowerBound = 1

Dim lngFormNumber As Long
Dim strFormName As String

'Requires reference to Microsoft DAO 3.6 Object Library (or 3.51
forAccess 97). Dim db As DAO.Database
Dim rst As DAO.Recordset

'Generate a random number in the specified range. See 'Rnd
Function' in the help file for details. Randomize Timer
lngFormNumber = Int((lngcUpperBound - lngcLowerBound + 1) * Rnd +
lngcLowerBound)

'Open a recordset to get the form name corresponding to the
random number. Set db = CurrentDb
Set rst = db.OpenRecordse("SELECT FormName FROM tblFormList WHERE
FormNumber = " & lngFormNumber) strFormName =
rst.Fields("FormName") rst.Close

'Open the form.
DoCmd.OpenForm strFormName

I get an error of a user defined-type not defined when running the
following lines. Dim db As DAO.Database
Dim rst As DAO.Recordset

This is code I received on this newgroup, thanks to Brendan Reynolds
for his help. Anyone have any idea how to fix the error I am running
Access '02 on windows 2000.

Thanks As Always,
RIP

You see this comment here?
'Requires reference to Microsoft DAO 3.6 Object Library (or 3.51
forAccess 97).

Brendan is telling you that you have to add a reference in your VB
project to the DAO object library. Since you're using Access 2000,
that'll be the Microsoft DAO 3.6 Object Library. To add the reference,
open the VB Editor, click Tools -> References..., locate the library
name in the list of available references, and put a check mark in the
box next to it. Close the dialog and you're good to go.
 

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