DoCmd.OpenForm with parameter

  • Thread starter NuBie via AccessMonster.com
  • Start date
N

NuBie via AccessMonster.com

DoCmd.OpenForm "Fuel", , , "[customer] = '" & cboCustomers & "'",
acFormReadOnly

The above code works fine. However, I'm looking for a more efficient way to
retrieve records based on the selection from combo box. The code above
retrieves "ALL" records then filters it. (Retrieves 100 records and shows 15)

I'm thinking of this :

[Forms].[Fuel].[RecordSource] = "SELECT * from Fuel WHERE [customer] = '" &
cboCustomers & "'"

where I want to retrieve ONLY records that meet the criteria. (Retrieves and
shows 15 records) When i tried the second snippet I got a runtime error 438.
Object doesnt support this property or method.

Or is there other way to achieve this? (using a query with params maybe?)
 
C

Clifford Bass

Hi,

You could use a query as the record source. In that query it would
have the limiting condition, which would reference the form where that holds
the combo box. So if the following is named "qrySelectedCustomer", your
form's Record Source would be "qrySelectedCustomer".

SELECT *
FROM Fuel
WHERE [customer] = [Forms]![frmFormWithComboBox]![cboCustomers];

Clifford Bass
 

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

Top