A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Autocounter



 
 
Thread Tools Display Modes
  #1  
Old May 16th, 2008, 04:17 PM posted to microsoft.public.access
an
external usenet poster
 
Posts: 345
Default Autocounter

Hi!

I would like to insert a counter, for exemple in F_Main, to count how many
times the DB was loaded.
Is it possible in Acc2k7, please?

Thanks in advance.
an
  #2  
Old May 16th, 2008, 06:18 PM posted to microsoft.public.access
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default Autocounter

One way is to build a table with number field and an update query that adds
one to the number field. Create a macro named Autoexec with action to open
the query.
Every time someone opens the database the macro will run and increment the
field.
--
KARL DEWEY
Build a little - Test a little


"an" wrote:

Hi!

I would like to insert a counter, for exemple in F_Main, to count how many
times the DB was loaded.
Is it possible in Acc2k7, please?

Thanks in advance.
an

  #3  
Old May 16th, 2008, 06:32 PM posted to microsoft.public.access
strive4peace
external usenet poster
 
Posts: 1,670
Default Autocounter

Hi an,

you need to store the information somewhere -- for instance, in a table
or a database property. I will give you the solution for counting how
many times your main form is opened and store the result in a table.

make a table:

*Defaults*
NumMainOpen, number, long

put one record in the table with NumMainOpen = 0

then, on the Open event of f_main:

'~~~~~~~~~
dim strSQL as string
strSQL = "UPDATE Defaults " _
& " SET NumMainOpen = NumMainOpen + 1;"

currentdb.execute strSQL
'~~~~~~~~~

Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
(: have an awesome day
*




an wrote:
Hi!

I would like to insert a counter, for exemple in F_Main, to count how many
times the DB was loaded.
Is it possible in Acc2k7, please?

Thanks in advance.
an

  #4  
Old May 16th, 2008, 06:38 PM posted to microsoft.public.access
Arvin Meyer [MVP]
external usenet poster
 
Posts: 4,231
Default Autocounter

Understand that each user must have their own copy of the front-end of the
database. Sharing a single fron-end is a leading cause of corruption.

Build a 1 record table named tblDBOpen, with a single field named CountDB.
Add the following code to a standard or form module and call it from the
form's open or load event:

Function CountOpen() As Long
On Error GoTo Error_Handler

Dim rst As DAO.Recordset
Dim lngMax As Long
Dim db As DAO.Database

Set db = CurrentDb

Set rst = db.OpenRecordset("Select Max(CountDB) As MaxNum FROM
tblDBOpen")
If IsNull(rst!MaxNum) Then
'no records yet, start with one
lngMax = 1
Else
lngMax = rst!MaxNum + 1
End If

CountOpen = lngMax

Exit_He
rst.Close
Set rst = Nothing
Set db = Nothing
Exit Function

Error_Handler:
MsgBox Err.Number & ": " & Err.Description
Resume Exit_Here

End Function
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com
"an" wrote in message
...
Hi!

I would like to insert a counter, for exemple in F_Main, to count how many
times the DB was loaded.
Is it possible in Acc2k7, please?

Thanks in advance.
an



  #5  
Old May 16th, 2008, 07:18 PM posted to microsoft.public.access
an
external usenet poster
 
Posts: 345
Default Autocounter

Thanks for your reply.

When debug run: Ok.
When form open return next error: CurrentDb.Execute strSQL

Thanks
an

"strive4peace" wrote:

Hi an,

you need to store the information somewhere -- for instance, in a table
or a database property. I will give you the solution for counting how
many times your main form is opened and store the result in a table.

make a table:

*Defaults*
NumMainOpen, number, long

put one record in the table with NumMainOpen = 0

then, on the Open event of f_main:

'~~~~~~~~~
dim strSQL as string
strSQL = "UPDATE Defaults " _
& " SET NumMainOpen = NumMainOpen + 1;"

currentdb.execute strSQL
'~~~~~~~~~

Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
(: have an awesome day
*




an wrote:
Hi!

I would like to insert a counter, for exemple in F_Main, to count how many
times the DB was loaded.
Is it possible in Acc2k7, please?

Thanks in advance.
an


  #6  
Old May 16th, 2008, 07:32 PM posted to microsoft.public.access
strive4peace
external usenet poster
 
Posts: 1,670
Default Autocounter

did you make the table?


** debug.print ***

debug.print strSQL

-- this prints a copy of the SQL statement to the debug window (CTRL-G)

After you execute your code, open the Debug window
CTRL-G to Goto the debuG window -- look at the SQL statement

If the SQL statement has an error

1. Make a new query (design view)

2. choose View, SQL from the menu
(or SQL from the toolbar, first icon)

3. cut the SQL statement from the debug window
(select, CTRL-X)

4. paste into the SQL window of the Query
(CTRL-V)

5. run ! from the SQL window
-- Access will tell you where the problem is in the SQL


Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
(: have an awesome day
*




an wrote:
Thanks for your reply.

When debug run: Ok.
When form open return next error: CurrentDb.Execute strSQL

Thanks
an

"strive4peace" wrote:

Hi an,

you need to store the information somewhere -- for instance, in a table
or a database property. I will give you the solution for counting how
many times your main form is opened and store the result in a table.

make a table:

*Defaults*
NumMainOpen, number, long

put one record in the table with NumMainOpen = 0

then, on the Open event of f_main:

'~~~~~~~~~
dim strSQL as string
strSQL = "UPDATE Defaults " _
& " SET NumMainOpen = NumMainOpen + 1;"

currentdb.execute strSQL
'~~~~~~~~~

Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
(: have an awesome day
*




an wrote:
Hi!

I would like to insert a counter, for exemple in F_Main, to count how many
times the DB was loaded.
Is it possible in Acc2k7, please?

Thanks in advance.
an

  #7  
Old May 16th, 2008, 07:34 PM posted to microsoft.public.access
strive4peace
external usenet poster
 
Posts: 1,670
Default Autocounter

Hi Arvie smile ... hope you don't mind my affectionate name for you

Warm Regards,
Crystal

*
(: have an awesome day
*




Arvin Meyer [MVP] wrote:
Understand that each user must have their own copy of the front-end of the
database. Sharing a single fron-end is a leading cause of corruption.

Build a 1 record table named tblDBOpen, with a single field named CountDB.
Add the following code to a standard or form module and call it from the
form's open or load event:

Function CountOpen() As Long
On Error GoTo Error_Handler

Dim rst As DAO.Recordset
Dim lngMax As Long
Dim db As DAO.Database

Set db = CurrentDb

Set rst = db.OpenRecordset("Select Max(CountDB) As MaxNum FROM
tblDBOpen")
If IsNull(rst!MaxNum) Then
'no records yet, start with one
lngMax = 1
Else
lngMax = rst!MaxNum + 1
End If

CountOpen = lngMax

Exit_He
rst.Close
Set rst = Nothing
Set db = Nothing
Exit Function

Error_Handler:
MsgBox Err.Number & ": " & Err.Description
Resume Exit_Here

End Function

  #8  
Old May 16th, 2008, 07:41 PM posted to microsoft.public.access
an
external usenet poster
 
Posts: 345
Default Autocounter

Thank you for replay.

One difficult: After insert your the function code in form, how call it
from's open or load event, please?

an

"Arvin Meyer [MVP]" wrote:

Understand that each user must have their own copy of the front-end of the
database. Sharing a single fron-end is a leading cause of corruption.

Build a 1 record table named tblDBOpen, with a single field named CountDB.
Add the following code to a standard or form module and call it from the
form's open or load event:

Function CountOpen() As Long
On Error GoTo Error_Handler

Dim rst As DAO.Recordset
Dim lngMax As Long
Dim db As DAO.Database

Set db = CurrentDb

Set rst = db.OpenRecordset("Select Max(CountDB) As MaxNum FROM
tblDBOpen")
If IsNull(rst!MaxNum) Then
'no records yet, start with one
lngMax = 1
Else
lngMax = rst!MaxNum + 1
End If

CountOpen = lngMax

Exit_He
rst.Close
Set rst = Nothing
Set db = Nothing
Exit Function

Error_Handler:
MsgBox Err.Number & ": " & Err.Description
Resume Exit_Here

End Function
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com
"an" wrote in message
...
Hi!

I would like to insert a counter, for exemple in F_Main, to count how many
times the DB was loaded.
Is it possible in Acc2k7, please?

Thanks in advance.
an




  #9  
Old May 16th, 2008, 07:50 PM posted to microsoft.public.access
an
external usenet poster
 
Posts: 345
Default Autocounter

Yes, it is...
Thanks

"strive4peace" wrote:

did you make the table?


** debug.print ***

debug.print strSQL

-- this prints a copy of the SQL statement to the debug window (CTRL-G)

After you execute your code, open the Debug window
CTRL-G to Goto the debuG window -- look at the SQL statement

If the SQL statement has an error

1. Make a new query (design view)

2. choose View, SQL from the menu
(or SQL from the toolbar, first icon)

3. cut the SQL statement from the debug window
(select, CTRL-X)

4. paste into the SQL window of the Query
(CTRL-V)

5. run ! from the SQL window
-- Access will tell you where the problem is in the SQL


Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
(: have an awesome day
*




an wrote:
Thanks for your reply.

When debug run: Ok.
When form open return next error: CurrentDb.Execute strSQL

Thanks
an

"strive4peace" wrote:

Hi an,

you need to store the information somewhere -- for instance, in a table
or a database property. I will give you the solution for counting how
many times your main form is opened and store the result in a table.

make a table:

*Defaults*
NumMainOpen, number, long

put one record in the table with NumMainOpen = 0

then, on the Open event of f_main:

'~~~~~~~~~
dim strSQL as string
strSQL = "UPDATE Defaults " _
& " SET NumMainOpen = NumMainOpen + 1;"

currentdb.execute strSQL
'~~~~~~~~~

Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
(: have an awesome day
*




an wrote:
Hi!

I would like to insert a counter, for exemple in F_Main, to count how many
times the DB was loaded.
Is it possible in Acc2k7, please?

Thanks in advance.
an


  #10  
Old May 16th, 2008, 07:51 PM posted to microsoft.public.access
an
external usenet poster
 
Posts: 345
Default Autocounter

Yes, it is.
I go to try!!!
an

"strive4peace" wrote:

did you make the table?


** debug.print ***

debug.print strSQL

-- this prints a copy of the SQL statement to the debug window (CTRL-G)

After you execute your code, open the Debug window
CTRL-G to Goto the debuG window -- look at the SQL statement

If the SQL statement has an error

1. Make a new query (design view)

2. choose View, SQL from the menu
(or SQL from the toolbar, first icon)

3. cut the SQL statement from the debug window
(select, CTRL-X)

4. paste into the SQL window of the Query
(CTRL-V)

5. run ! from the SQL window
-- Access will tell you where the problem is in the SQL


Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
(: have an awesome day
*




an wrote:
Thanks for your reply.

When debug run: Ok.
When form open return next error: CurrentDb.Execute strSQL

Thanks
an

"strive4peace" wrote:

Hi an,

you need to store the information somewhere -- for instance, in a table
or a database property. I will give you the solution for counting how
many times your main form is opened and store the result in a table.

make a table:

*Defaults*
NumMainOpen, number, long

put one record in the table with NumMainOpen = 0

then, on the Open event of f_main:

'~~~~~~~~~
dim strSQL as string
strSQL = "UPDATE Defaults " _
& " SET NumMainOpen = NumMainOpen + 1;"

currentdb.execute strSQL
'~~~~~~~~~

Warm Regards,
Crystal

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
(: have an awesome day
*




an wrote:
Hi!

I would like to insert a counter, for exemple in F_Main, to count how many
times the DB was loaded.
Is it possible in Acc2k7, please?

Thanks in advance.
an


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 03:33 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.