Store label1.text to database

Posted on 2006-04-06
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
    LVL 85

    Expert Comment

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

    What kind of "database" are you using?

    Author Comment

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

    Accepted Solution

    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

    Thanks vinnyd79 works great

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    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…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now