Solved

Databases in Visual Basic

Posted on 1997-05-12
1
581 Views
Last Modified: 2013-11-25
I am trying to use the data manager to create a database of stock (barcode, price, description, number of stock,  etc..) and I don`t know how to get Visual Basic to enter the data base and read the info and then update the number of stock after a sale.
Thanks in advance
Daniel Journo
daniel@journo.nwnet.co.uk
0
Comment
Question by:danieljourno
1 Comment
 
LVL 7

Accepted Solution

by:
tward earned 100 total points
ID: 1426221
Below is a set of functions that I created so I could just add it to a project and open databases and create dynasets.

To Do updates easily just look up the ExecuteSql method..

  Option Explicit
 
  Public SQL$
  Public DatabaseName$
 
  Public dbDatabase As Database
  Public dbWorkspace As Workspace
 
  Public DynaSetOpenError As Boolean

'''''''''''''''''''''''''''''''''''''''''''''''''''
'    Function:  CloseDynaSet()                    '
'                                                 '
' Description:  Closes the Open Dynaset.          '
'                                                 '
'       Input:  None.                             '
'                                                 '
'      Output:  None.                             '
'                                                 '
'     Returns:  Nothing into the DynaSet Object.  '
'                                                 '
'''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function CloseDynaSet() As Object

  Set CloseDynaSet = Nothing

End Function


'''''''''''''''''''''''''''''''''''''''''''''''''''
'    Function:  DatabaseClose()                   '
'                                                 '
' Description:  Closes an Open Access Database.   '
'               Database should have been opened  '
'               using OpenDatabase.               '
'                                                 '
'       Input:  NONE.                             '
'                                                 '
'      Output:  Clears Database connection '
'                                                 '
'     Returns:  NONE.                             '
'                                                 '
'''''''''''''''''''''''''''''''''''''''''''''''''''
Public Sub DatabaseClose()
 
  On Error Resume Next
 
  Set dbWorkspace = Nothing
  Set dbDatabase = Nothing
  Set DBEngine = Nothing

End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''
'    Function:  DatabaseOpen(DATABASE$)           '
'                                                 '
' Description:  Opens the Database Passed to it   '
'               in DATABASE.                      '
'                                                 '
'       Input:  DATABASE$ - "Path+Name of File"   '
'                                                 '
'      Output:  Message Box on Error, otherwise   '
'               an Open Database Object.          '
'                                                 '
'     Returns:   True = Database was Opened.      '
'               False = Database Open Failed.     '
'                                                 '
'''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function DatabaseOpen(ByVal DatabaseName$) As Boolean
 
  DatabaseOpen = True
 
  On Error Resume Next
  Set dbWorkspace = DBEngine.Workspaces(0)
  Set dbDatabase = dbWorkspace.OpenDatabase(DatabaseName$)
 
  If Err.Number <> 0 Then
   
    MsgBox "Access Error:  " & Err.Description, vbOKOnly + vbCritical, "Access Database Open Error...."
    DatabaseOpen = False
   
  End If
   
End Function

'''''''''''''''''''''''''''''''''''''''''''''''''''
'    Function:  OpenDynaset(SQL$)                 '
'                                                 '
' Description:  Opens a Dynaset using the SQL$    '
'               SQL Statement passed to it.       '
'                                                 '
'       Input:  SQL$ - Any valid SQL Statement.   '
'                                                 '
'      Output:  An Open Dynaset, Use CloseDynaset '
'               to Close Dynasets.                '
'                                                 '
'     Returns:  The OpenDynaset Object.           '
'                                                 '
'''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function OpenDynaSet(ByVal SQL$) As Object

  On Error Resume Next

  DynaSetOpenError = False
 
  Set OpenDynaSet = dbDatabase.OpenRecordset(SQL$, dbOpenDynaset)
 
  If Err.Number <> 0 Then

    Call MsgBox("Error #" & Err.Number & ":  " & Err.Description, vbCritical + vbOKOnly, "SQL Query Error.....")

    DynaSetOpenError = True
   
  ElseIf OpenDynaSet.RecordCount = 0 Then
       
        Call MsgBox("No Records Found for Query:  " & SQL$, vbExclamation + vbOKOnly, "No Records Found.....")

        DynaSetOpenError = True
 
  Else
   
    OpenDynaSet.MoveLast
    OpenDynaSet.MoveFirst

  End If
  On Error GoTo 0

End Function

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

708 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

13 Experts available now in Live!

Get 1:1 Help Now