-
I am opening a database with the above code but need it to open "adOpenKeyset" so that the dataGrid will be editable. Opens read only forward only by default and that does me no good. Here is the code: If cboContact.Text = "Home Alone" Then
Dim adoParameter As Parameter
Set adoConnect = New Connection
Set adoRecordset = New Recordset
adoConnect.CursorLocation = adUseClient
adoConnect.Open _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\HomeAlone\db1.mdb;Persist Security Info=False"
Set adoCommand = New Command
adoCommand.CommandText = "SELECT * from qryHaContactSearch WHERE City = ?"
Set adoParam = New Parameter
adoParam.Name = "City"
adoParam.Type = adVarChar
adoParam.Size = 20
adoParam.Value = Me.txtCity.Text
adoCommand.Parameters.Append adoParam
Set adoCommand.ActiveConnection = adoConnect
Set adoRecordset = adoCommand.Execute
Set DataGrid1.DataSource = adoRecordset
End If
I can't find a way to work it in so any help would be wildly appreciated. It's all I have left to finish my first big project. Thanks in advance :)
Bill
-
Bill,
Instead of using
Set adoRecordset = adoCommand.Execute
try this:
Set adoRecordset.Source = adoCommand
adoRecordset.CursorLocation = adUseClient
adoRecordset.CursorType = adOpenKeyset
adoRecordset.Open
-
Thanks so much!
That worked out perfectly! I just had to add the lock type to optimistic because it's read only by default and it works! That was the last piece of a 4 month project and I thank you to no end! Your friend,
Bill
-
Glad that I could help. :)
-
Hi!
try adding this to your code,
adoConnect.CursorType = adOpenKeyset