BadSikander
Registered User.
- Local time
- Today, 14:36
- Joined
- Jan 19, 2007
- Messages
- 31
Hello.
I'm not very good with lookups, but from a button click I need to check what record ID's are found in a query, and then carry out different actions for each one that is present. The query contains minimum zero records and maximum forty records at all times.
I am doing this currently using dlookups like this:
If IsNull(DLookup("[CC SID]", "[CC Centres]", "[CC SID] = 1")) Then
Do this
Else
Do that
End If
If IsNull(DLookup("[CC SID]", "[CC Centres]", "[CC SID] = 2")) Then
Do this
Else
Do that
End If
If IsNull(DLookup("[CC SID]", "[CC Centres]", "[CC SID] = 3")) Then
Do this
Else
Do that
End If
... and so on, forty times.
I'm guessing this isn't a very efficient way of doing it, and it certainly runs very slowly, presumably because the query is being re-run for each dlookup.
Is there any way to alter this so the query is only looked at once, perhaps using a case statement? i.e. have a single dlookup check which of a series of potential record ID's are present, then still have a different action carried out for each?
Alternatively, if I was to bind the relevant query to a background form, could the dlookups be made to refer to that "already open" version of the query rather than running it again from scratch each time?
Or use a For loop of some kind instead?
I'm not very good with lookups, but from a button click I need to check what record ID's are found in a query, and then carry out different actions for each one that is present. The query contains minimum zero records and maximum forty records at all times.
I am doing this currently using dlookups like this:
If IsNull(DLookup("[CC SID]", "[CC Centres]", "[CC SID] = 1")) Then
Do this
Else
Do that
End If
If IsNull(DLookup("[CC SID]", "[CC Centres]", "[CC SID] = 2")) Then
Do this
Else
Do that
End If
If IsNull(DLookup("[CC SID]", "[CC Centres]", "[CC SID] = 3")) Then
Do this
Else
Do that
End If
... and so on, forty times.
I'm guessing this isn't a very efficient way of doing it, and it certainly runs very slowly, presumably because the query is being re-run for each dlookup.
Is there any way to alter this so the query is only looked at once, perhaps using a case statement? i.e. have a single dlookup check which of a series of potential record ID's are present, then still have a different action carried out for each?
Alternatively, if I was to bind the relevant query to a background form, could the dlookups be made to refer to that "already open" version of the query rather than running it again from scratch each time?
Or use a For loop of some kind instead?
Last edited: