Solved

Visual Basic Database

Posted on 1997-10-13
6
206 Views
Last Modified: 2013-11-25
Does anybody have any simple databases that I could have to learn from? Perhaps a database that will work with a Access
File which could have basic features such as add,delete,next,previous,etc...  

I need to learn by example and most resources you go to only show small steps but never show you the whole picture.

Also, if you could recommend a newbie to some VB books that might have some good samples to learn from?
0
Comment
Question by:brewman
6 Comments
 

Author Comment

by:brewman
ID: 1437486
Edited text of question
0
 
LVL 1

Expert Comment

by:Chrrris
ID: 1437487
Is there any particular reason for wanting to use Visual Basic
rather than MS Access?
0
 
LVL 9

Accepted Solution

by:
cymbolic earned 200 total points
ID: 1437488
I hear you loud and clear.  With all the different methods and cursor types to choose from, it's really hard to get that first clear picture of how to manage databases in VB.  I found a good comprehensive review of the methods, including history of the Access database (Jet engine) to be "Hitchhiker's Guide to Visual Basic & SQL Server" by William R. Vaughn, published by Microsoft Press.

If you have VB installed, look at the VISDATA project in the Samples directory.  Also, go into your help system in VB, and start at the DBEngine help, then review Workspaces, then the dataBase object, then the recordset object, paying particular attention to the recordset object and it's example, and the different options for recordset cursor type specification, which determine whether you have an updateable recordset, which you need to use the .edti/.addnew/.update methods.  This is the heirarchy of the objects you need to work with to use the JET engine (or DAO) to process Access files (.MDB).

Problem is, it's not just the DAO methods you need to know, you also should become conversant in SQL to be able to use the .execute method.

If this doesn't get you where you want to be, I'll clip out some code examples.   A good sample is in the OPENDATABASE method:
Function UpdateNorthwind () As Integer
      Dim MyWorkspace As Workspace, MyDatabase As Database
      Dim MyTable As Recordset
      Dim MyFile As String
      Dim ErrorCondition As Integer
      UpdateDb = True

MyFile = "MYDB.MDB"      ' Define name of database.
      On Error GoTo DBErrorHandler      ' Enable error trapping.

Set MyWorkspace = Workspaces(0)
      ' Open database.
      Set MyDatabase = MyWorkspace.OpenDatabase(MyFile)
      If Not ErrorCondition Then
            On Error GoTo TableErrorHandler      ' Enable error trapping.
            ' Open table.
            Set MyTable = MyDatabase.OpenRecordset("Employees")
            If Not ErrorCondition Then
                  On Error GoTo EditErrorHandler      ' Enable error trapping.
                  Do Until MyTable.EOF
                        If MyTable![Title] = "Sales Representative" Then
                              MyTable.Edit      ' Enable editing.
                              MyTable![Title] = "Account Executive"   ' Make changes.

MyTable.Update      ' Save changes.
                        End If
                        MyTable.MoveNext      ' Move to next record.
                  Loop

MyTable.Close      ' Close table.

End If

MyDatabase.Close      ' Close database.

End If

On Error GoTo 0      ' Disable error trapping.

Exit Function
DBErrorHandler:
      ErrorCondition = True
      UpdateDb = False
      MsgBox "Can't open database.", vbExclamation
      Resume Next
TableErrorHandler:
      ErrorCondition = True
      UpdateDb = False
      MsgBox "Can't open Employees table.", vbExclamation
      Resume Next
EditErrorHandler:
      ErrorCondition = True
      UpdateDb = False
      MsgBox "Can't edit Employees table.", vbExclamation
      Resume Next
End Function

Although, I wouldn't recommend you use table processing if you are developing multiuser, shared applications, because you will be locking tables to do it.  Instead, use read only recordsets, then use execute methods to directly update individual records (but don't worry about this until you get something working).
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:brewman
ID: 1437489
Thanks, you gave me alot to think about!  The reason I want to learn this VB is too eventually use this with Web Design in the future. Take care!
0
 
LVL 1

Expert Comment

by:lmarceau
ID: 1437490
Imarceau,  Thanks for you input also...  You are right on the money!  I am sick of spending $$ for every new endevour I have.  I just got through with a phase of writing PERL scripts and spent about a total of 100$ in books..  I know that all my interests will eventually pay off.     I mostly do this as a hobby that hopefully someday will work with my Telecommunications work I am already involved with.     --Thanks...
0
 

Author Comment

by:brewman
ID: 1437491
Don't get your heart set on really fast access (even in Access!) especially if you get into ODBC setups.  When (if) you do get to that point, using the trace log in your odbc setup information is a real eye opener regarding the volumes of ODBC transactions required to get a single resultset.

Also, if you are thinking about going to shared, multiuser applications, get the VB enterprise edition, and skip right over using DAO and Access databases.  You need to consider using something like Oracle or SQL server, and RDO as an access method.  Access and Jet just won't scale up to a real muliuser application.

Yeah, I know what you mean about the books.  Nothing's under $50 bucks, and you can't shoot a 30-30 through any of 'em!(but you want to)  I think I'm gettng tennis elbow just hauling 'em around! (I scan any book first at Barnes & Noble, because most of 'em turn out to be rehashed help system text!)
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

813 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now