Results 1 to 12 of 12

Thread: Connection function

  1. #1

    Thread Starter
    Fanatic Member SeaHag's Avatar
    Join Date
    Jul 2001
    Location
    Lake Huron
    Posts
    901

    Connection function

    How do i create a function to return a
    Access table that i may read from somwhere
    else in my project.

    This is what i have so far... but I think its returning the
    wrong thing... as well where would i use the .close ?

    VB Code:
    1. Public Function getRecordset(Table As String) As Recordset
    2. Dim dbsBlastRoom As Database
    3.  
    4.  
    5. Set dbsBlastRoom = OpenDatabase(App.Path & "\blstroom.mdb")
    6. Set getRecordset = dbsBlastRoom.OpenRecordset(Table)
    7.  
    8. myRecordset.Close
    9. dbsBlastRoom.Close
    10. End Function
    11.  
    12.  
    13. Seahag

  2. #2
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    u r using DAO?????

  3. #3

    Thread Starter
    Fanatic Member SeaHag's Avatar
    Join Date
    Jul 2001
    Location
    Lake Huron
    Posts
    901
    yes

  4. #4
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    You should close it after you are done with it e.g.
    Code:
    myRST = getRecordset("MyTable")
    'do code with myRST here
    myRST.close

  5. #5

    Thread Starter
    Fanatic Member SeaHag's Avatar
    Join Date
    Jul 2001
    Location
    Lake Huron
    Posts
    901
    K.. I get error though


    VB Code:
    1. Private Sub Command1_Click()
    2. Dim myRecorset As Recordset
    3. Set myRecorset = getRecordset("blstpot")
    4.  
    5. myRecorset.MoveFirst
    6.             Debug.Print myRecorset(1)
    7.  
    8. myRecorset.Close
    9.  
    10. End Sub
    11.  
    12.  
    13.  
    14. Public Function getRecordset(Table As String) As Recordset
    15. Dim dbsBlastRoom As Database
    16. Dim rstRecord As Variant
    17.  
    18.     Set dbsBlastRoom = OpenDatabase(App.Path & "\blstroom.mdb")
    19.     Set rstRecord = dbsBlastRoom.OpenRecordset(Table)
    20.  
    21.             getRecordset = rstRecord ' *** i get error here " INVALID USE OF PROPERTY
    22.      
    23.     rstRecord.Close
    24.     dbsBlastRoom.Close
    25. End Function

  6. #6
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    On the line where error occurs

    VB Code:
    1. Set getRecordset = rstRecord

  7. #7

    Thread Starter
    Fanatic Member SeaHag's Avatar
    Join Date
    Jul 2001
    Location
    Lake Huron
    Posts
    901
    Yuppers.. then I get another error
    under the click event for the command button. (ot of scope
    or something)

    I have done some searching.. I don't thing this will be
    economical.
    Maybe a DB class or something.. and even thats not worth
    the time.. for this project that is.

    I just thought it would be easy


    thnks.

  8. #8
    Hyperactive Member rEaL iGoR's Avatar
    Join Date
    Apr 2001
    Location
    A secret!
    Posts
    417
    It would be alot easier if you worked with ADO instead of DAO...
    VB, ADO, SQL, 3DSMAX, DHTML, VBscript, Javascript, CSS

    -Lars Espen Rosness

  9. #9
    Registered User Virus00110's Avatar
    Join Date
    Jul 2002
    Location
    Williamsport, PA
    Posts
    290
    this is the only way i was able to get it to work but it would be easier if you were using ADO.

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim myRecorset As Recordset
    3. Set myRecorset = getRecordset("blstpot")
    4.  
    5. myRecorset.MoveFirst
    6.             Debug.Print myRecorset(1)
    7.  
    8. myRecorset.Close
    9.  
    10. End Sub
    11.  
    12.  
    13.  
    14. Public Function getRecordset(Table As String) As Recordset
    15. Dim dbsBlastRoom As Database
    16. Dim rstRecord As Variant
    17.  
    18.     Set dbsBlastRoom = OpenDatabase(App.Path & "\blstroom.mdb")
    19.     Set rstRecord = dbsBlastRoom.OpenRecordset(Table)
    20.  
    21.             Set getRecordset = rstRecord ' *** i get error here " INVALID USE OF PROPERTY
    22.      
    23.     'Take out or comment out the following two lines like i have done.
    24.     'rstRecord.Close
    25.     'dbsBlastRoom.Close
    26. End Function

  10. #10

    Thread Starter
    Fanatic Member SeaHag's Avatar
    Join Date
    Jul 2001
    Location
    Lake Huron
    Posts
    901
    Ya. thats the way i got it to work too..

    How will ADO help me.. ?

    are the variables different ? recordsets different?

    Thanks all

  11. #11
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    I think you have to dig deep into DB programming to realize the benefits of ADO programming.

  12. #12

    Thread Starter
    Fanatic Member SeaHag's Avatar
    Join Date
    Jul 2001
    Location
    Lake Huron
    Posts
    901
    So.. Dao is great for opening a database
    grabbing info and populating an array?

    Can anyone else sell ADO?


    seahag

Posting Permissions

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



Click Here to Expand Forum to Full Width