F5 key (1 Viewer)

leebop

New member
Local time
Today, 16:10
Joined
Jan 4, 2004
Messages
9
Can anyone tell me why this key does not run the code, but open the macro box??

I also cannot seem to get code to work when i eneter

set rec = db. (there are no pop up boxes)

Help please
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 11:10
Joined
Feb 19, 2002
Messages
43,470
You'll have a better chance at the correct answer if you post the actual code. You can crop out just a few lines if it is lengthy but there is no way for us to acertain syntax errors from your post.
 

leebop

New member
Local time
Today, 16:10
Joined
Jan 4, 2004
Messages
9
Option Compare Database

Private Sub Form_Open(Cancel As Integer)

Dim rec As Recordset

set rec = db.



End Sub

I don't understand why the pop up box with OpenRecordSet is not appearing
 

WayneRyan

AWF VIP
Local time
Today, 16:10
Joined
Nov 19, 2002
Messages
7,122
leebop,

I think that your code needs to look more like this. When you
have it in design mode check that the Microsoft DAO reference
is checked and has a higher priority than the ADO reference.

Also, I don't think that your code was running at that time.
The current line should be highlighted in yellow. F8 is single-step
and F5 will run to completion.

Code:
Option Compare Database

Private Sub Form_Open(Cancel As Integer)
Dim dbs As DAO.Database
Dim rec As DAO.Recordset

Set dbs = CurrentDb
set rec = dbs.OpenRecordSet("SomeTable")

hth,
Wayne
 

leebop

New member
Local time
Today, 16:10
Joined
Jan 4, 2004
Messages
9
Thanks Wayne.

Havedone as u sugested but the pop up boxes still don't appear.
 

leebop

New member
Local time
Today, 16:10
Joined
Jan 4, 2004
Messages
9
Wayne,
I attach the DB.

It is on the on open property of the from frmStudentMenu, that i'm trying to do this
 

Attachments

  • test.zip
    50.2 KB · Views: 108

WayneRyan

AWF VIP
Local time
Today, 16:10
Joined
Nov 19, 2002
Messages
7,122
leebop,

I downloaded the db, but the form you refer to is an empty form
with no controls or recordsource. There is no code in the form's
Open event.

What are we trying to do? I need more info.

Wayne
 

leebop

New member
Local time
Today, 16:10
Joined
Jan 4, 2004
Messages
9
Wayne,
i want to addbuttons to the form.

the buttons will only be active if there are records in the table tblStudentDetails.

i therefore wanted the form to open, look in the tbalementioned above, ani if the recordcount > 0 enable the buttons.

however i thought that pop up boxes would help ie when i typed

set rec = dp. (i expected a pop box hear with dbOpenRecordSet).

Does that make it clearer??

Thanks.,
Lee
 

WayneRyan

AWF VIP
Local time
Today, 16:10
Joined
Nov 19, 2002
Messages
7,122
leebop,

OK, I need a few minutes for something else.

Wayne
 

WayneRyan

AWF VIP
Local time
Today, 16:10
Joined
Nov 19, 2002
Messages
7,122
Leebop,

I used a DCount function to check the number of records, but
this code could have done it too.

Code:
Private Sub Form_Open(Cancel As Integer)
Dim dbs As DAO.Database
Dim rec As DAO.Recordset

Set dbs = CurrentDb
set rec = dbs.OpenRecordSet("tblStudentDetails")
rec.MoveLast
If rec.RecordCount > 0 Then
  ' button visible
Else
  ' button invisible
End If

Wayne
 

Attachments

  • e2e.zip
    46.3 KB · Views: 95

leebop

New member
Local time
Today, 16:10
Joined
Jan 4, 2004
Messages
9
Thanks Wayne.

Should i be getting pop-up menu's though????
 

WayneRyan

AWF VIP
Local time
Today, 16:10
Joined
Nov 19, 2002
Messages
7,122
leebop,

I don't know what you mean by pop-up menus. What is
happening exactly? If you are not "running" code, I think that
the F5 key brings up a dialog box pertaining to Macros. I don't
use macros, so I don't know for sure. If your code is executing
(meaning that your form is in the process of opening) then this
won't happen.

In code design view, F5 means one thing, when your code is
running it means another.

Wayne
 

WayneRyan

AWF VIP
Local time
Today, 16:10
Joined
Nov 19, 2002
Messages
7,122
leebop,

I just had a thought. If you just want to see your code "run"
then you can do either of the following:

Put the word "Stop" in you code. When the code runs, Access
will stop and highlight the word "Stop". Put the cursor on the
next line of code and type Ctrl-F9. The new line will be
highlighted. Then F8 will single-step and F5 will run to
completion.

Or click at the left margin on a line of code. A solid circle will
appear and Access will stop when it encounters this. This is
a breakpoint. Procede as above.

hth,
Wayne
 

=TB=

Registered User.
Local time
Today, 16:10
Joined
Aug 13, 2002
Messages
68
Leebob

I might be wrong but is this where you are getting confused

F5 runs your application in VisualBasic/Studio enviroment - it does not in access visual basic though.
 

Jon K

Registered User.
Local time
Today, 16:10
Joined
May 22, 2002
Messages
2,209
Code:
[b]Dim rec As Recordset
set rec = db.[/b]

I don't understand why the pop up box with 
OpenRecordSet is not appearing
You haven't told Access what db is (See the attached screenshot image).

Wayne has given you the code that works.
 

Attachments

  • screenshot.jpg
    screenshot.jpg
    38.2 KB · Views: 82
Last edited:

BoroLee

Registered User.
Local time
Today, 16:10
Joined
Aug 30, 2000
Messages
90
JonK,
This is wot i mean exactly.

When i typed set rec=db. the pop-up did not appear.

Any idea's why????
 

Mile-O

Back once again...
Local time
Today, 16:10
Joined
Dec 10, 2002
Messages
11,316
You need to Dim db As DAO.Database. and then Set db = CurrentDB

As it stands db means nothing to the editor.
 

Mile-O

Back once again...
Local time
Today, 16:10
Joined
Dec 10, 2002
Messages
11,316
And Dim rec As DAO.Recordset is better as it's more explicit.
 

Mile-O

Back once again...
Local time
Today, 16:10
Joined
Dec 10, 2002
Messages
11,316
Because db is nothing. It's just two letters. db is not a VBA keyword.

You are intending to use db as an object variable but you have not dimensioned it.

The reason I say it's better to use DAO. before the Database and Recordset objects is that there are two methods for accessing data in this way: DAO and ADO. Explicitly stating which you wish to use helps to speed up code (ever so slightly) and can reduce errors if your database has references to both data access methods.
 

Users who are viewing this thread

Top Bottom