[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

Putting data into access database from visual basic program

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?
1 Solution
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.
<%@ 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

KiriusAuthor Commented:
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.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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
KiriusAuthor Commented:
tobydavid Worked perfectly was exactly what I was looking for.
Great.  Glad to have helped.


Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now