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

x
?
Solved

Saving label caption to access database

Posted on 2003-03-15
2
Medium Priority
?
211 Views
Last Modified: 2013-12-26
Hi
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.

Thanks
Andy
0
Comment
Question by:AndyPany
2 Comments
 
LVL 28

Accepted Solution

by:
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
cn.Open
' open recordset
Set rs = New ADODB.Recordset
rs.Open "Select * From DBTableName", cn, adOpenKeyset, adLockOptimistic
' add new record to Table
rs.AddNew
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
rs.Update
' close recordset
rs.Close
Set rs = Nothing
' close connection
cn.Close
Set cn = Nothing
End Sub
0
 

Author Comment

by:AndyPany
ID: 8146789
Hi  vinnyd79

Thanks worked well. check out my next question.

Andy
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

580 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