Saving label caption to access database

Posted on 2003-03-15
Medium Priority
Last Modified: 2013-12-26
I am currently learning vb and have started to design a piece of software for recording temperatures, I admit I have used extracts from someone elses code.  My problem is I can show the current temp on the 3 seperate labels I am using and can then use print to make a csv text file, however I would like some sample code to save direct into access I also need to save the date and time with each temperature recorded.  I am refreshing the temperature on the label every 30 seconds.

Question by:AndyPany
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 28

Accepted Solution

vinnyd79 earned 500 total points
ID: 8144921
here is an example:

add a refence to Microsoft ActiveX Data Objects Library:

Private Sub Command1_Click()
Dim DataBase As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
DataBase = "C:\MyDataBase"
' 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
' add new record to Table
rs.Fields("Temp1").Value = lblTemp1.Caption
rs.Fields("Temp2").Value = lblTemp2.Caption
rs.Fields("Temp3").Value = lblTemp3.Caption
rs.Fields("TempDate1").Value = lblTempDate1.Caption
rs.Fields("TempDate2").Value = lblTempDate2.Caption
rs.Fields("TempDate3").Value = lblTempDate3.Caption
' close recordset
Set rs = Nothing
' close connection
Set cn = Nothing
End Sub

Author Comment

ID: 8146789
Hi  vinnyd79

Thanks worked well. check out my next question.


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

770 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