|
-
Oct 31st, 2000, 01:03 PM
#5
Lively Member
For database access I've written several class modules to handle this for me, one for MSAccess databases, one for Oracle databases, etc. I know this would require a little code re-writing on your part but you would then have an object that can be used over and over again. For example the following code would deal with an MSAccess database:
Private dbDatabase As Database
Public recRecordset As Recordset
Private mstrQuery As String
Public Property Let Query(strQuery As String)
mstrQuery = strQuery
End Property
Public Property Get Query() As String
Query = mstrQuery
End Property
Public Sub OpenDB()
Set dbDatabase = Workspaces(0).OpenDatabase _
(App.Path & "\IsoTrack.mdb")
Set recRecordset = dbDatabase.OpenRecordset(Query)
End Sub
Public Sub CloseDB()
On Error Resume Next
recRecordset.Close
dbDatabase.Close
End Sub
Public Sub AddAsNew()
With recRecordset
.AddNew
Save_Members
.Update
End With
End Sub
Private Sub Save_Members()
With recRecordset
.Fields("AreaID") = frmArea.strArea
.Fields("IsometricLineNumber") = frmArea.strIsoNum
.Fields("Size") = frmArea.intPipeDia
.Fields("Spec") = frmArea.strSpec
End With
End Sub
The Save_Members sub could be written outside of the class module and called so that the database object is totally generic. In this instance, my database object is tied to a specific table. Of course, to call the object from your code would look something like this:
In the General Declarations section:
Private DB As New clsAccessDB
In the Form Load event:
Private Sub Form_Load()
Set DB = New clsAccessDB
End Sub
Private Sub cmdSaveToDB_Click()
strQuery = "SELECT LineNumberSize FROM IsoLines WHERE" _
& " LineNumberSize='" & arrNewNumSize(I) & "'"
DB.OpenDB strQuery
strArea = "Blah"
strIsoNum = "WooHoo"
strSize = "Giant"
strSpec = "Asbestos"
DB.AddAsNew
DB.CloseDB
End Sub
I know I didn't really answer your question, but I hope this helps!
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
|