Easy? How to store a value for later use.

G

Guest

Hi all

I need a label to store a value with the record count of a table. I managed to update the label anytime the form is opened and the record count is done, but everytime I close the application the label's caption is reset, and since the label is on the main form when I open the application again the label is not up to date. Where can I store the current recordcount value in order to have it on the label.caption property next time I launch the application

Thank you very much

Kind Regards

Max
 
N

Nikos Yannacopoulos

Max,

This is not the way to do it. You can change a label caption at runtime, but
not save that change. You need a table to store values into, so they are
available next time you open your database.

HTH,
Nikos

Max said:
Hi all,

I need a label to store a value with the record count of a table. I
managed to update the label anytime the form is opened and the record count
is done, but everytime I close the application the label's caption is reset,
and since the label is on the main form when I open the application again
the label is not up to date. Where can I store the current recordcount value
in order to have it on the label.caption property next time I launch the
application?
 
G

Guest

Hi Nikos, thanks for your answer
Do you have by chance a sample of the code I should use to store the value into the table? I'm not that good .... :
Thanks
Ma


----- Nikos Yannacopoulos wrote: ----

Max

This is not the way to do it. You can change a label caption at runtime, bu
not save that change. You need a table to store values into, so they ar
available next time you open your database

HTH
Niko

Max said:
managed to update the label anytime the form is opened and the record coun
is done, but everytime I close the application the label's caption is reset
and since the label is on the main form when I open the application agai
the label is not up to date. Where can I store the current recordcount valu
in order to have it on the label.caption property next time I launch th
application
 
P

Phil Hunt

If you can manage to update the label caption at one time, you should
execute that routine everytime the form is shown.
I may be wrong, but you really dont need to store that number in the DB,
becasuse it is dynamic

Max said:
Hi all,

I need a label to store a value with the record count of a table. I
managed to update the label anytime the form is opened and the record count
is done, but everytime I close the application the label's caption is reset,
and since the label is on the main form when I open the application again
the label is not up to date. Where can I store the current recordcount value
in order to have it on the label.caption property next time I launch the
application?
 
N

Nikos Yannacopoulos

Max,

How do you get the recordcount to put in the label in the first place? Do
you use a macro or VB code? Which event fires it?

Also: have a look at Phil Hunt's reply, he seems to have a point; why do you
need to store it? Maybe there is a better way to get what you want, for
instance using a date/time stamp field in your data table, so at any time
you can count the number of records created after date/time X or between
dates X and Y etc.

Nikos

Max said:
Hi Nikos, thanks for your answer.
Do you have by chance a sample of the code I should use to store the value
into the table? I'm not that good .... :)
 
G

Guest

Hey Nikos and Phil

currently I am updating the lable with the following line
lblNumSparTot.Caption = "Spartiti catalogati al " & Format(Date, "dd/mm/yy") & ": " & Me.RecordsetClone.RecordCoun
abd this is in the current event of the "me" form
The fact is that this and other statistics have to be displyed on the first form that is loaded (switchboard) when the application is opened, so at that point the other forms that are associated to the recordsets are not loaded yet and I cannot use the Me.RecordsetClone.RecordCount code. And load all the forms hidden at the same time with the switchboard will be too much, there are several tables with thousands of records. So I was wondering if there is some code I can put in the form load of the switchboard to count the records in all the tables that are not open in any form

Thanks a lot

Massim



----- Nikos Yannacopoulos wrote: ----

Max

How do you get the recordcount to put in the label in the first place? D
you use a macro or VB code? Which event fires it

Also: have a look at Phil Hunt's reply, he seems to have a point; why do yo
need to store it? Maybe there is a better way to get what you want, fo
instance using a date/time stamp field in your data table, so at any tim
you can count the number of records created after date/time X or betwee
dates X and Y etc

Niko

Max said:
Hi Nikos, thanks for your answer
Do you have by chance a sample of the code I should use to store the valu
into the table? I'm not that good .... :
 
G

Guest

Hey Nikos and Phil

currently I am updating the lable with the following line
lblNumSparTot.Caption = "Spartiti catalogati al " & Format(Date, "dd/mm/yy") & ": " & Me.RecordsetClone.RecordCoun
abd this is in the current event of the "me" form
The fact is that this and other statistics have to be displyed on the first form that is loaded (switchboard) when the application is opened, so at that point the other forms that are associated to the recordsets are not loaded yet and I cannot use the Me.RecordsetClone.RecordCount code. And load all the forms hidden at the same time with the switchboard will be too much, there are several tables with thousands of records. So I was wondering if there is some code I can put in the form load of the switchboard to count the records in all the tables that are not open in any form

Thanks a lot

Massim


----- Phil Hunt wrote: ----

If you can manage to update the label caption at one time, you shoul
execute that routine everytime the form is shown
I may be wrong, but you really dont need to store that number in the DB
becasuse it is dynami

Max said:
managed to update the label anytime the form is opened and the record coun
is done, but everytime I close the application the label's caption is reset
and since the label is on the main form when I open the application agai
the label is not up to date. Where can I store the current recordcount valu
in order to have it on the label.caption property next time I launch th
application
 
N

Nikos Yannacopoulos

Massimo,

So you're trying to count the records in tables, not actually store some
value, as your original posting suggested?
Well, there might be a better solution, but here's one I can offer: open the
tables as recordsets and count the records directly from there, rather than
depending on forms. Here's some sample code that may help:

Sub get_recordcount()
Dim rst As DAO.Recordset
For Each tbl In CurrentDb.TableDefs
If Left(tbl.Name, 4) <> "MSys" Then
Set rst = CurrentDb.OpenRecordset(tbl.Name)
rst.MoveLast
Debug.Print tbl.Name, rst.RecordCount
rst.Close
End If
Next
Set rst = Nothing
End Sub

HTH,
Nikos



Max said:
Hey Nikos and Phil,

currently I am updating the lable with the following line:
lblNumSparTot.Caption = "Spartiti catalogati al " & Format(Date,
"dd/mm/yy") & ": " & Me.RecordsetClone.RecordCount
abd this is in the current event of the "me" form.
The fact is that this and other statistics have to be displyed on the
first form that is loaded (switchboard) when the application is opened, so
at that point the other forms that are associated to the recordsets are not
loaded yet and I cannot use the Me.RecordsetClone.RecordCount code. And load
all the forms hidden at the same time with the switchboard will be too much,
there are several tables with thousands of records. So I was wondering if
there is some code I can put in the form load of the switchboard to count
the records in all the tables that are not open in any form.
 
P

Phil Hunt

if you are using Access, there is DCOUNT function which may satisfy your
need.


Max said:
Hey Nikos and Phil,

currently I am updating the lable with the following line:
lblNumSparTot.Caption = "Spartiti catalogati al " & Format(Date,
"dd/mm/yy") & ": " & Me.RecordsetClone.RecordCount
abd this is in the current event of the "me" form.
The fact is that this and other statistics have to be displyed on the
first form that is loaded (switchboard) when the application is opened, so
at that point the other forms that are associated to the recordsets are not
loaded yet and I cannot use the Me.RecordsetClone.RecordCount code. And load
all the forms hidden at the same time with the switchboard will be too much,
there are several tables with thousands of records. So I was wondering if
there is some code I can put in the form load of the switchboard to count
the records in all the tables that are not open in any form.
 
G

Guest

Hi Nikos,

sorry for the delay, I wasn't in the office for a while; I just wanted to thank you cause I've used the sample code you gave me and it works perfectly.

Have a nice day!

Max

----- Nikos Yannacopoulos wrote: -----

Massimo,

So you're trying to count the records in tables, not actually store some
value, as your original posting suggested?
Well, there might be a better solution, but here's one I can offer: open the
tables as recordsets and count the records directly from there, rather than
depending on forms. Here's some sample code that may help:

Sub get_recordcount()
Dim rst As DAO.Recordset
For Each tbl In CurrentDb.TableDefs
If Left(tbl.Name, 4) <> "MSys" Then
Set rst = CurrentDb.OpenRecordset(tbl.Name)
rst.MoveLast
Debug.Print tbl.Name, rst.RecordCount
rst.Close
End If
Next
Set rst = Nothing
End Sub

HTH,
Nikos



Max said:
Hey Nikos and Phil,
lblNumSparTot.Caption = "Spartiti catalogati al " & Format(Date,
"dd/mm/yy") & ": " & Me.RecordsetClone.RecordCount
abd this is in the current event of the "me" form.
The fact is that this and other statistics have to be displyed on the
first form that is loaded (switchboard) when the application is opened, so
at that point the other forms that are associated to the recordsets are not
loaded yet and I cannot use the Me.RecordsetClone.RecordCount code. And load
all the forms hidden at the same time with the switchboard will be too much,
there are several tables with thousands of records. So I was wondering if
there is some code I can put in the form load of the switchboard to count
the records in all the tables that are not open in any form.
 

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