searcking on key

S

Sharkbyte

John:

VBA code doesn't really like to do searches. When you run a SQL statement,
from code, in needs to be an action statement: DELETE, UPDATE, INSERT.

Sharkbyte
 
J

John

So if I need to set my form to the record with key 12345, what do I do?

Thanks

Regards
 
S

Sharkbyte

John:

Okay. That's a little different...

I'm going to guess that you are running a form/subform combination, and the
subform populates based on the value in your main form (or something similar).

So, your question is how to move to a specific record...

1. You can set the Default Value property, on the control displaying your
key, to "12345"

2. Or, you can use an If statement, during an event, to set the value based
on a set of criteria. Such as:

(In the After Update event of Control1)

If Control1 = "9876" then
Control2 = "12345"
Else
End If

HTH

Sharkbyte
 
J

John

Not precisely. The user is on the form with record id = 5678 which has a
field which has 12345 as the current record's duplicate. In this case the
user just want to press a button to go to the record with id in the
duplicate field i.e. 12345.

Thanks

Regards
 
D

Douglas J. Steele

The OpenForm method lets you specify a WHERE clause.

DoCmd.OpenForm "MyForm", acNormal, , "ID = 12345"

Assuming that you've got 12345 stored in a variable strID, that would be

DoCmd.OpenForm "MyForm", acNormal, , "ID = " & strID
 
D

Douglas J Steele

You could try applying a filter instead, then.

Me.Filter = "ID = 12345"
Me.FilterOn = True

To turn the filter off, have a button that does


Me.Filter = vbNullString
Me.FilterOn = False
 
Top