Solved

Visual Basic Database

Posted on 1997-10-13
6
209 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
[X]
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
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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

738 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