J
J
Hello all! Two simple questions I have not been able to find the
answer to online. (1) Is ADO better in this case? (2) How is my ADO
syntax?
ORIGINAL DLOOKUP METHOD:
Dim SearchFor as Integer
SearchFor = 23 'This is just an example
txtControl1 = Dlookup("[MyTableReturnValue1]","MyTable","[MyTableKey]="
& SearchFor )
txtControl2 = Dlookup("[MyTableReturnValue2]","MyTable","[MyTableKey]="
& SearchFor )
txtControl3 = Dlookup("[MyTableReturnValue3]","MyTable","[MyTableKey]="
& SearchFor )
'...
txtControl7= Dlookup("[MyTableReturnValue7]","MyTable","[MyTableKey]="
& SearchFor )
NEW ADO RECORDSET METHOD:
Dim SearchFor as Integer
SearchFor = 23
Set objRecordSet = CreateObject("ADODB.Recordset")
objRecordSet.Open "SELECT * FROM [MyTable]", _
CurrentProject.Connection, adOpenStatic, adLockOptimistic
objRecordSet.Find "[MyTableKey]=" & SearchFor
'I realize I could add a WHERE to my SQL statement but let's ignore
that for now
txtControl1 = objRecordSet.Fields.Item("MyTableReturnValue1")
txtControl2 = objRecordSet.Fields.Item("MyTableReturnValue2")
txtControl3 = objRecordSet.Fields.Item("MyTableReturnValue3")
'...
txtControl7 = objRecordSet.Fields.Item("MyTableReturnValue7")
That's it! So to review:
(1) Is ADO better in this case?
(2a) How is my ADO syntax?
(2b) Was I suppose to 'close' or 'release' the recordset when I'm done?
Thanks in advance for your insight,
~J
answer to online. (1) Is ADO better in this case? (2) How is my ADO
syntax?
ORIGINAL DLOOKUP METHOD:
Dim SearchFor as Integer
SearchFor = 23 'This is just an example
txtControl1 = Dlookup("[MyTableReturnValue1]","MyTable","[MyTableKey]="
& SearchFor )
txtControl2 = Dlookup("[MyTableReturnValue2]","MyTable","[MyTableKey]="
& SearchFor )
txtControl3 = Dlookup("[MyTableReturnValue3]","MyTable","[MyTableKey]="
& SearchFor )
'...
txtControl7= Dlookup("[MyTableReturnValue7]","MyTable","[MyTableKey]="
& SearchFor )
NEW ADO RECORDSET METHOD:
Dim SearchFor as Integer
SearchFor = 23
Set objRecordSet = CreateObject("ADODB.Recordset")
objRecordSet.Open "SELECT * FROM [MyTable]", _
CurrentProject.Connection, adOpenStatic, adLockOptimistic
objRecordSet.Find "[MyTableKey]=" & SearchFor
'I realize I could add a WHERE to my SQL statement but let's ignore
that for now
txtControl1 = objRecordSet.Fields.Item("MyTableReturnValue1")
txtControl2 = objRecordSet.Fields.Item("MyTableReturnValue2")
txtControl3 = objRecordSet.Fields.Item("MyTableReturnValue3")
'...
txtControl7 = objRecordSet.Fields.Item("MyTableReturnValue7")
That's it! So to review:
(1) Is ADO better in this case?
(2a) How is my ADO syntax?
(2b) Was I suppose to 'close' or 'release' the recordset when I'm done?
Thanks in advance for your insight,
~J