brianjessup
Registered User.
- Local time
- Today, 07:37
- Joined
- May 25, 2003
- Messages
- 36
What's the best way to search a recordset in VBA to see if several criteria match in a record?
For example, after a few controls are set, I'd like to search for any records matching those settings. Once found, I'd like to be able to edit a few other fields in that record via some txtboxes on the form and then save the record to my table.
Once the record is found, is it possible to then use a field to set a control?
For example, one of my controls on the form is a combobox, the first column (hidden) of which has the table key for each item - ie a number unique to that item. This is what is stored in the recordset I'm searching. Once a record is found matching things like date, location, etc, I'd like the same combobox to use the ID# to display the item name - or in other words I'd like to set the combobox to the item based on the hidden key. Is that possible?
How to return data to a function?
And finally, a restatement or addendum to the idea expressed in the first section. Once I get these records, I'd like to take data from a field, display it in a txtbox, edit it as i like and then (after the usual user prompts) save it.
I have a few basic steps here:
Set rst = New ADODB.Recordset
rst.Open "RawResults", CurrentProject.Connection, adOpenKeyset, adLockOptimistic, adCmdTable
With rst
.MoveFirst
.Find "Day = 1"
Do While Not .EOF
'these next two if statements just check the other settings to
'make sure they match what I'm looking for
If Me!txtSetting1 = rst.Fields("Setting1") Then
If Me!FrameFinals = rst.Fields("Finals") Then
'load data
'set other controls
End If
End If
loop
End With
rst.close
Set rst= nothing
End Sub
For example, after a few controls are set, I'd like to search for any records matching those settings. Once found, I'd like to be able to edit a few other fields in that record via some txtboxes on the form and then save the record to my table.
Once the record is found, is it possible to then use a field to set a control?
For example, one of my controls on the form is a combobox, the first column (hidden) of which has the table key for each item - ie a number unique to that item. This is what is stored in the recordset I'm searching. Once a record is found matching things like date, location, etc, I'd like the same combobox to use the ID# to display the item name - or in other words I'd like to set the combobox to the item based on the hidden key. Is that possible?
How to return data to a function?
And finally, a restatement or addendum to the idea expressed in the first section. Once I get these records, I'd like to take data from a field, display it in a txtbox, edit it as i like and then (after the usual user prompts) save it.
I have a few basic steps here:
Set rst = New ADODB.Recordset
rst.Open "RawResults", CurrentProject.Connection, adOpenKeyset, adLockOptimistic, adCmdTable
With rst
.MoveFirst
.Find "Day = 1"
Do While Not .EOF
'these next two if statements just check the other settings to
'make sure they match what I'm looking for
If Me!txtSetting1 = rst.Fields("Setting1") Then
If Me!FrameFinals = rst.Fields("Finals") Then
'load data
'set other controls
End If
End If
loop
End With
rst.close
Set rst= nothing
End Sub