Open Form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
I using the docmd.openform command to open a form. I would like to be able
to limit the records by only opening certain ones. The form that I am opening
has a field called [tank]. I would like to only see records where [tank] =
"DF101". The form opens correctly but no data is being shown.
Thanks
 
Greg,
open the form in design mode and then select the Data Tab and then paste the
following into the Form's Record Source. But first replace "MyTableName" with
the actual name of your table that has the data. Take care & God Bless.

SELECT MyTableName.*
FROM MyTableName
WHERE (((MyTableName.Tank)="DF101"));


-- ~ SPARKER ~
 
Looks like a left out a very important part of my question. The database has
37 tanks. I have a command button for each one and need to display the
corresponding records accordingly. I appreciate your quick response.
Thanks

sparker said:
Greg,
open the form in design mode and then select the Data Tab and then paste the
following into the Form's Record Source. But first replace "MyTableName" with
the actual name of your table that has the data. Take care & God Bless.

SELECT MyTableName.*
FROM MyTableName
WHERE (((MyTableName.Tank)="DF101"));


-- ~ SPARKER ~


Greg said:
Hello,
I using the docmd.openform command to open a form. I would like to be able
to limit the records by only opening certain ones. The form that I am opening
has a field called [tank]. I would like to only see records where [tank] =
"DF101". The form opens correctly but no data is being shown.
Thanks
 
Greg said:
Hello,
I using the docmd.openform command to open a form. I would like to be able
to limit the records by only opening certain ones. The form that I am opening
has a field called [tank]. I would like to only see records where [tank] =
"DF101". The form opens correctly but no data is being shown.
Thanks

The OpenForm Method of the DoCmd object includes an optional WHERE argument for
exactly this purpose.

DoCmd.OpenForm "FormName",,,,"[tank] = 'DF101'"

If you wanted the filter to be dynamically set by a ComboBox on the calling
form...

DoCmd.OpenForm "FormName",,,,"[tank] = '" & Me.ComboBoxName & "'"
 
When you type the command in the VBA window, you'll be given a list of
optional parameters one of which is the WHERE parameter.

DoCmd.OpenForm "frmReservations", view, filter, WHERE, datamode,
windowmode, openArguements

so try

DoCmd.OpenForm "frmReservations", view, FILTER, "[tank]='DF101'",
datamode, windowmode, openArguements

Note the use of single apostrophes surrounding DF101. Anytime you're
encapsulating a text value within double apostrophes, you'll need to use
singles.
 
Must be a pretty big DB to have 37 tanks in it.

If you want to open a form from another by using a command button on the
first then change the WHERE statement to

.... , "[tank] = " & Me.controlName , ...

where controlName is the control on the first form that contains an
unique identifier for the record, which in this case I assume is DF101
Looks like a left out a very important part of my question. The database has
37 tanks. I have a command button for each one and need to display the
corresponding records accordingly. I appreciate your quick response.
Thanks

:

Greg,
open the form in design mode and then select the Data Tab and then paste the
following into the Form's Record Source. But first replace "MyTableName" with
the actual name of your table that has the data. Take care & God Bless.

SELECT MyTableName.*
FROM MyTableName
WHERE (((MyTableName.Tank)="DF101"));


-- ~ SPARKER ~


:

Hello,
I using the docmd.openform command to open a form. I would like to be able
to limit the records by only opening certain ones. The form that I am opening
has a field called [tank]. I would like to only see records where [tank] =
"DF101". The form opens correctly but no data is being shown.
Thanks
 
That did the trick. I left out the single apostrophes. Thank you to all that
responded.
Have a blessed day.

David C. Holley said:
When you type the command in the VBA window, you'll be given a list of
optional parameters one of which is the WHERE parameter.

DoCmd.OpenForm "frmReservations", view, filter, WHERE, datamode,
windowmode, openArguements

so try

DoCmd.OpenForm "frmReservations", view, FILTER, "[tank]='DF101'",
datamode, windowmode, openArguements

Note the use of single apostrophes surrounding DF101. Anytime you're
encapsulating a text value within double apostrophes, you'll need to use
singles.
Hello,
I using the docmd.openform command to open a form. I would like to be able
to limit the records by only opening certain ones. The form that I am opening
has a field called [tank]. I would like to only see records where [tank] =
"DF101". The form opens correctly but no data is being shown.
Thanks
 
Back
Top