Putting data into access database from visual basic program

Posted on 2006-11-08
Last Modified: 2010-04-16
What I have is a program for checking leaks. The user inputs the pressures and temps and calcs the difference and displays this to the user. What I want to do is on the form the users fills in serial number and a couple other fields including pressures and temperatures and then pushes the calc button. When the button is pushed it calcs the difference and inputs all the information into a database.

Is this possible?
Question by:Kirius
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

Expert Comment

ID: 17901931
Yes, it is definitely possible. The easy part--once you know how to do it--is building the program.

What you are describing is using an Access backend for a Visual Basic application. An alternative would be to use VB code in Access to build an Access application to do the same thing.

The hard part is packaging the program and installing it on a user's machine because you will be dealing with issues regarding Microsoft's Data Access Components (MDAC) that are absent on some Windows 98 and earlier machines, and present, but with differing versions on Windows XP machines. The Packaging and Deployment Wizard in VB is not very helpful when it comes to the installation of the MDAC, so you have to resort to C++ scripts with Windows Studio Installer or another installation tool. If you know you will only be dealing with Windows XP machines, you may get away without hassling with an MDAC update/installation.

As an alternative to the VB/Access route, which would involve installing a program on all the users' machines, I would suggest using PHP and MySQL via a website to run your program. That way, it will work on Windows and Mac, there won't be any software to install, and your users can access the program from any internet-capable device.

Expert Comment

ID: 17903631
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data.OleDb" %>  

That means we will use VB as the default coding language and we are going to use OLEDB .NET data provider. Now, here's the code for doing simple query using ADO.NET

<script language="vb" runat="server">

Sub Page_Load(sender as Object, e as EventArgs)
  'Get the Database Path, to be used in DB Connection String
  Dim sDBPath As String = Request.MapPath(".") & "\NWind.mdb"

  'Define DB Connection String
  Dim sCnnString As String = "Provider=Microsoft.Jet.Oledb.4.0;" & _
                             "Data Source=" & sDBPath

  'Define variables as input for our sql query
  Dim temperature As String  = txtTemp.Text.ToString
  Dim difference As String = txtDifference.Text.ToString
  Dim pressure As String = txtPressure.Text.ToString

  'Populate Connection Object
  Dim oCnn As New OleDbConnection(sCnnString)

  'Define our sql query
  Dim sSQL As String = "insert into tablename
(differene, pressure, temperature)
values ('Argos', 'Indiana', '89', '46501');"

  'Populate Command Object
  Dim oCmd As New OledbCommand(sSQL, oCnn)


'Opening Connection for our DB operation  

'Execute the query


    'Closing the data reader & connection object
  End Try
End Sub

 i dunno what kind od code and fileds ur using


Author Comment

ID: 17908608
Well actually what I have is a form with the text boxes of SerialNumber Retest EmpNumber StartPSi EndPSI StartTemp EndTemp LeakLocation, once these are filled it it does a calculation to see whether or not there is a leak. Once this is done I want this information placed into an access database. Maybe this helps a little more. Just 1 table corresponding to those txt boxes and a label named Time.
Independent Software Vendors: 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!


Accepted Solution

tobydavid earned 125 total points
ID: 17914269
This would be the general routine for the calc button:

Private Sub CalcBtn_Click()
Dim db As Database
Dim tb As TableDef
Dim rs As Recordset
‘*** Perform Calulation ***
‘ ….
‘*** Update Data Table ***
Set db = OpenDatabase("D:\...\....mdb")  ' Your dataset path an name
Set tb = db.TableDefs("YourTableName")
Set rs = tb.OpenRecordset
On Error Resume Next
rs.Fields("FieldName1") = Value1
rs.Fields("FieldName2") = Value2
rs.Fields("FieldName3") = Value3
rs.Bookmark = rs.LastModified

End Sub

Author Comment

ID: 17914661
tobydavid Worked perfectly was exactly what I was looking for.

Expert Comment

ID: 17914682
Great.  Glad to have helped.


Featured Post

Technology Partners: 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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this post we will learn different types of Android Layout and some basics of an Android App.
Six Sigma Control Plans
Introduction to Processes

690 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