Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Store label1.text to database

Posted on 2006-04-06
Medium Priority
Last Modified: 2012-05-05

I have a need to store a label.text value to a database every 30 seconds; how can I do this?  Please be specific

The database is local in the app
Question by:NCSO
  • 2
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16395100
"The database is local in the app"

What kind of "database" are you using?

Author Comment

ID: 16395158
it is a small access database used to capture latitude and longitude
LVL 28

Accepted Solution

vinnyd79 earned 1000 total points
ID: 16395162
Here is a basic example that uses a Timer to add a labels caption to a database every 30 seconds. This example is using a MS Access Database:

' add a reference to Microsoft ActiveX Data Objects Library:
Dim DataBase As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset

Private Sub Form_Load()
Timer.Interval = 30000
Timer1.Enabled = True
DataBase = "C:\MyDataBase.mdb"

' open Database Connection
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & DataBase & "'"
cn.CursorLocation = adUseClient

' open recordset
Set rs = New ADODB.Recordset
rs.Open "Select * From DBTableName", cn, adOpenKeyset, adLockOptimistic

End Sub

Private Sub Timer1_Timer()

' add new record to Table
rs.Fields("YourFieldName").Value = Label1.Caption

End Sub

Private Sub Form_Unload(Cancel As Integer)
' close recordset
Set rs = Nothing

' close connection
Set cn = Nothing
End Sub

Author Comment

ID: 16400999
Thanks vinnyd79 works great

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question