2

I'm sure there's a simple solution to this, but it seems to elude me.

So I have a form with a RecordSource of SELECT * FROM Table1 WHERE id=[@id]. (Yes, I know SELECT * is evil; it's just an example). Obviously the default behavior of this form is that upon opening, an input dialog will prompt for the "[@id]" value. But what I would like to do is call this form from VBA and instead of having the input dialog pop up, go ahead and tell the form what [@id] is, so the dialog never pops up, and the form opens just as if [@id] where replaced by a value in the query. I've tried the following so far...

Form_MyForm.RecordSource = String.Replace(Form_Form1.RecordSource, "[@id]", 1)
DoCmd.OpenForm "MyForm"

...and...

Form_MyForm.txtId.Value = 1
DoCmd.OpenForm "MyForm"

...and...

DoCmd.OpenForm "MyForm", acNormal, , "[@id]=" & 1

...but none of them seem to have the desired effect. How do i do this?

Thanks ahead of time.

Stephen Collins
  • 3,523
  • 8
  • 40
  • 61

1 Answers1

2

See if it's easier to drop the WHERE clause from your query:

SELECT * FROM Table1;

Then use the optional WhereCondition parameter with Openform to indicate which id value you want:

DoCmd.OpenForm "MyForm", WhereCondition:="id = 1"
HansUp
  • 95,961
  • 11
  • 77
  • 135