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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|