Visual Basic 6 & Access 2000


Closed Thread
Results 1 to 34 of 34

Hybrid View

  1. #1
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154

    Default Visual Basic 6 & Access 2000

    Hi,

    This thread is meant as a meeting place for discussion about VB6 and Access in PIC/USB-related projects.

    Keith, this tutorial explains database access much better than the Step By Step or Programmer's Guide books from Microsoft that came with my VB6 package.

    http://www.vbexplorer.com/VBExplorer...er_ADO_DAO.asp

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  2. #2
    Join Date
    Oct 2004
    Location
    Italy
    Posts
    695


    Did you find this post helpful? Yes | No

    Default

    Hi,

    A better title for this thread would be:

    Visul Basic 6.0 & ADO/Jet database engine

    Best regards,

    Luciano

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Not really 'cause I'm using Access to store the data. I'll have tons of questions on that too so I thought this would be a nice place to put them.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  4. #4
    Join Date
    Mar 2005
    Location
    Iowa, USA
    Posts
    216


    Did you find this post helpful? Yes | No

    Default Stored Queries

    One cool thing I've done in the past is utilized stored queries to minimize code. These are similar to stored procedures if you utilize Oracle. You basically create a common sql statement in access, then call that in your vb app (ASP in my case) with the parameters required for the stored query. Here's an example of what I've done.... keep in mind it is for an ASP webpage, but should be similar for VB.

    Code:
    *****************************************************
    <%
    	' -- InsertProc.asp --
    %>
    <html>
    <head>
    	<title>Running Stored Procedures in Access Database (Insert Value)</title>
        <style>p { font-family:verdana,arial; font-size:10pt; font-weight:bold; }</style>
    </head>
    <body><p>
    <%	
    	' Connection String
    	Dim connStr
    		connStr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ="
    		connStr = connStr & Server.MapPath("StoredProc.mdb") & ";PWD=Whateveryourpasswordis"
    
    		
    	' Connection Object
    	Dim con
    		Set con = Server.CreateObject("ADODB.Connection")
    		
    	' Recordset Object
    	Dim rs
    		
    		' connecting to database
    		con.Open connStr
    Here we execute the insertproc query
    		' executing stored procedure
    		Set rs = con.Execute ("exec InsertProc XXX") ' XXX is the data passed to the stored query
    Now run another stored query called SelectProc               		
    		Set rs = con.Execute ("exec SelectProc")
    		
    		' showing all records %>
    The code below just writes the table data to the web page
    		<table border="1" width="25%">
    		<%for each x in rs.Fields ' Write the field names in the table headers
    			response.write("<th>" & x.name & "</th>")
    		next%>
    		</tr>
    
    		<%do until rs.EOF ' Read thru each record %>
        		<tr>
    
        		<%for each x in rs.Fields ' Put the value of each field of the current record into the table 
           			Response.Write "<td>" & (x.value) & "</td>"
        		next
    
        		rs.MoveNext ' Move to the next record %>
        		</tr>
    		<%loop
    		' Close connections and release the objects in memory	
    		con.Close
    		Set rs = Nothing
    		Set con = Nothing
    
    
    %>
    </p></body>
    </html>
    *************************************************
    The access query is named InsertProc. And the query code looks like this....
    Code:
    INSERT INTO [Names] ( Name )
    VALUES ([@newName]);
    This simple query inserts the value you pass into Table Names into Field Name.
    The code for the SelectProc is this....
    Code:
    SELECT *
    FROM [Names];
    Anyway.... Thought this could be handy for others.
    Wisdom is knowing what path to take next... Integrity is taking it.
    Ryan Miller

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Here's an example of emptying a database and adding one record:

    Dim dbMenu As Database
    Dim rsMenu As Recordset

    Set dbMenu = OpenDatabase("E:\EasyHID\Xk1 v2\USBProject\VisualBASIC\Modified code\NR2003.mdb")
    Set rsMenu = dbMenu.OpenRecordset("SELECT * FROM tblMenu")

    If Not rsMenu.EOF Then
    rsMenu.Delete
    End If

    rsMenu.AddNew
    rsMenu!ptrMenu = 1
    rsMenu!RecordType = "1"
    rsMenu.Update

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  6. #6
    Join Date
    Oct 2004
    Location
    Italy
    Posts
    695


    Did you find this post helpful? Yes | No

    Exclamation

    Hi Robert,

    First you will have to decide which technology to use
    to access the Microsoft Jet database engine.

    The two options you have with VB 6.0 are:

    Microsoft Data Access Objects (DAO)
    Microsoft ActiveX Data Objects (ADO)

    Once decided, stick with one!

    My two cents advice is to use ADO.

    * * *

    Are you sure that the users of this forum
    are really interested in this stuff?

    There are hundred of forums and tutorials talking
    about VB, so why not search and subscribe there?

    Best regards,

    Luciano

Similar Threads

  1. Replies: 5
    Last Post: - 24th August 2006, 21:59
  2. Visual Basic 6 question
    By Christopher4187 in forum Off Topic
    Replies: 5
    Last Post: - 3rd July 2006, 13:06
  3. Visual Basic 6 and Pic com
    By shawn in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 15th September 2005, 05:21
  4. Output PIC module
    By freelancebee in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th September 2005, 20:10
  5. '877 and Visual Basic 6
    By Tomas in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 4th March 2004, 02:31

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts