searcking on key

  • Thread starter Thread starter John
  • Start date Start date
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
 
So if I need to set my form to the record with key 12345, what do I do?

Thanks

Regards
 
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
 
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
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top