Hi.
In my VBA modules, I connect to my data through ADO. I would like some feedback on the way I do things to see if I could be doing them "better".
Background:
The database is used in a small business, with usually no more than one person accessing the data at a time. Occassionally, there may be up to three people working with the data, but that would be unusual and they almost certainly would be working with unrelated records.
Here's some typical lines from my VBA:
Dim rs1 As ADODB.RecordSet
Set rs1 = New ADODB.RecordSet
rs1.Open "[...sql query goes here...]", CurrentProject.Connection, adOpenStatic, adLockOptimistic
...
...
rs1.close
set rs1 = nothing
I've read about the CursorType and LockType parameters, but the descriptions don't seem to mean that much to me, I'm afraid.
I typically use adOpenStatic. Does it matter what type of cursor I use in my environment? Because I usually open recordsets with SQL statements, do I have to worry about changes that other users may have made to the data?
For my LockType, again, in my environment, does it matter which one I use? For recordsets that I'm only reading from, and not updating or adding to, would it be better to use adLockReadOnly?
BONUS QUESTION:
Here's how I generally would add a record to a table via ADO. Please advise because I have a feeling that I am being stupid:
Set rs1 = New ADODB.RecordSet
'Sometimes I might throw a WHERE clause in here to reduce the number of records returned.
rs1.Open "SELECT FarmName, FarmDescription, Acreage, PrimaryStateID, PrimaryCountyID, ClientID FROM tblFarm", CurrentProject.Connection, adOpenStatic, adLockOptimistic
rs1.AddNew
With rs1
'Add data to each field in the new record.
![FarmName] = Trim(Me.txtFarmDataName.Value)
![FarmDescription] = Trim(Me.txtFarmDataDescription.Value)
![Acreage] = Trim(Me.txtFarmDataAcreage.Value)
![PrimaryStateID] = Me.cmbFarmDataState.Column(0, Me.cmbFarmDataState.ListIndex)
![PrimaryCountyID] = Me.cmbFarmDataCounty.Column(0, Me.cmbFarmDataCounty.ListIndex)
![ClientID] = Form_frmFarms.ClientIDF
.Update
End With
rs1.Close
Set rs1 = Nothing
Any tips would be well received. And I give you advance permission to make fun of me, if you want to.
Duluter
In my VBA modules, I connect to my data through ADO. I would like some feedback on the way I do things to see if I could be doing them "better".
Background:
The database is used in a small business, with usually no more than one person accessing the data at a time. Occassionally, there may be up to three people working with the data, but that would be unusual and they almost certainly would be working with unrelated records.
Here's some typical lines from my VBA:
Dim rs1 As ADODB.RecordSet
Set rs1 = New ADODB.RecordSet
rs1.Open "[...sql query goes here...]", CurrentProject.Connection, adOpenStatic, adLockOptimistic
...
...
rs1.close
set rs1 = nothing
I've read about the CursorType and LockType parameters, but the descriptions don't seem to mean that much to me, I'm afraid.
I typically use adOpenStatic. Does it matter what type of cursor I use in my environment? Because I usually open recordsets with SQL statements, do I have to worry about changes that other users may have made to the data?
For my LockType, again, in my environment, does it matter which one I use? For recordsets that I'm only reading from, and not updating or adding to, would it be better to use adLockReadOnly?
BONUS QUESTION:
Here's how I generally would add a record to a table via ADO. Please advise because I have a feeling that I am being stupid:
Set rs1 = New ADODB.RecordSet
'Sometimes I might throw a WHERE clause in here to reduce the number of records returned.
rs1.Open "SELECT FarmName, FarmDescription, Acreage, PrimaryStateID, PrimaryCountyID, ClientID FROM tblFarm", CurrentProject.Connection, adOpenStatic, adLockOptimistic
rs1.AddNew
With rs1
'Add data to each field in the new record.
![FarmName] = Trim(Me.txtFarmDataName.Value)
![FarmDescription] = Trim(Me.txtFarmDataDescription.Value)
![Acreage] = Trim(Me.txtFarmDataAcreage.Value)
![PrimaryStateID] = Me.cmbFarmDataState.Column(0, Me.cmbFarmDataState.ListIndex)
![PrimaryCountyID] = Me.cmbFarmDataCounty.Column(0, Me.cmbFarmDataCounty.ListIndex)
![ClientID] = Form_frmFarms.ClientIDF
.Update
End With
rs1.Close
Set rs1 = Nothing
Any tips would be well received. And I give you advance permission to make fun of me, if you want to.
Duluter