|
-
Aug 21st, 2002, 08:26 AM
#1
Thread Starter
Fanatic Member
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:
Public Function getRecordset(Table As String) As Recordset
Dim dbsBlastRoom As Database
Set dbsBlastRoom = OpenDatabase(App.Path & "\blstroom.mdb")
Set getRecordset = dbsBlastRoom.OpenRecordset(Table)
myRecordset.Close
dbsBlastRoom.Close
End Function
Seahag
-
Aug 21st, 2002, 08:39 AM
#2
Frenzied Member
-
Aug 21st, 2002, 08:40 AM
#3
Thread Starter
Fanatic Member
yes
-
Aug 21st, 2002, 08:42 AM
#4
Software Eng.
You should close it after you are done with it e.g.
Code:
myRST = getRecordset("MyTable")
'do code with myRST here
myRST.close
-
Aug 21st, 2002, 08:47 AM
#5
Thread Starter
Fanatic Member
K.. I get error though
VB Code:
Private Sub Command1_Click()
Dim myRecorset As Recordset
Set myRecorset = getRecordset("blstpot")
myRecorset.MoveFirst
Debug.Print myRecorset(1)
myRecorset.Close
End Sub
Public Function getRecordset(Table As String) As Recordset
Dim dbsBlastRoom As Database
Dim rstRecord As Variant
Set dbsBlastRoom = OpenDatabase(App.Path & "\blstroom.mdb")
Set rstRecord = dbsBlastRoom.OpenRecordset(Table)
getRecordset = rstRecord ' *** i get error here " INVALID USE OF PROPERTY
rstRecord.Close
dbsBlastRoom.Close
End Function
-
Aug 21st, 2002, 12:37 PM
#6
Frenzied Member
On the line where error occurs
VB Code:
Set getRecordset = rstRecord
-
Aug 21st, 2002, 02:37 PM
#7
Thread Starter
Fanatic Member
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.
-
Aug 21st, 2002, 02:43 PM
#8
Hyperactive Member
It would be alot easier if you worked with ADO instead of DAO...
VB, ADO, SQL, 3DSMAX, DHTML, VBscript, Javascript, CSS
-Lars Espen Rosness
-
Aug 21st, 2002, 02:58 PM
#9
Registered User
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:
Private Sub Command1_Click()
Dim myRecorset As Recordset
Set myRecorset = getRecordset("blstpot")
myRecorset.MoveFirst
Debug.Print myRecorset(1)
myRecorset.Close
End Sub
Public Function getRecordset(Table As String) As Recordset
Dim dbsBlastRoom As Database
Dim rstRecord As Variant
Set dbsBlastRoom = OpenDatabase(App.Path & "\blstroom.mdb")
Set rstRecord = dbsBlastRoom.OpenRecordset(Table)
Set getRecordset = rstRecord ' *** i get error here " INVALID USE OF PROPERTY
'Take out or comment out the following two lines like i have done.
'rstRecord.Close
'dbsBlastRoom.Close
End Function
-
Aug 21st, 2002, 03:03 PM
#10
Thread Starter
Fanatic Member
Ya. thats the way i got it to work too..
How will ADO help me.. ?
are the variables different ? recordsets different?
Thanks all
-
Aug 21st, 2002, 11:13 PM
#11
Software Eng.
I think you have to dig deep into DB programming to realize the benefits of ADO programming.
-
Aug 22nd, 2002, 07:15 AM
#12
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|