Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Databases in Visual Basic

Posted on 1997-05-12
1
Medium Priority
?
621 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
[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
1 Comment
 
LVL 7

Accepted Solution

by:
tward earned 200 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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 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…
Suggested Courses

715 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