Guy Boswell
Registered User.
- Local time
- Today, 20:36
- Joined
- Jul 20, 2009
- Messages
- 26
I am having problems with a form that tries to apply a filter I don't want when it is opened.
Can anyone please help me? 
* I have a database that generates flood warning messages
* The messages incorporate a weather forecast
* The weather forecasts are stored on a table, 'tblWeatherForecasts', as a memo, 'fldWeatherForecast'
* The other fields on the table are an auto number, 'fldForecastNumber', and a date stamp, 'fldForecastDate', set to now() when a new record is added.
* Form, 'frmWeatherForecasts', allows the user to add new weather forecasts
* Record source for the form is a query to ensure the latest record is shown first
SELECT tblWeatherForecasts.* FROM tblWeatherForecasts ORDER BY tblWeatherForecasts.fldForecastNumber DESC;
* No filter is set and Allow filters is set to No (I have tried Yes and that doesn't solve problem)
* An OnOpen event for the form checks if there is a recent weather forecast. The code is :
*****
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open
If DCount("fldWeatherForecast", "tblWeatherforecasts", "now()-fldForecastDate < 1") < 1 Then
MsgBox "Most recent weather forecast is more than 24 hours old. Copy todays forecast across from the Met Office e-mail or type in a summary situation.", , "No forecast!"
End If
'Error trapping code
Exit_Form_Open:
Exit Sub
Err_Form_Open:
MsgBox Err.Description, 0, "Form_Open!"
Resume Exit_Form_Open
End Sub
*****
So far, so good!
All of the above works exactly as it should. The form opens OK direct from the database window or from a button on Switchboard (built with switchboard wizard, 'Open form in edit mode')
* When the user clicks a button on a form to generate a flood message the procedure that runs checks there is a recent weather forecast before proceeding
* The relevant bit of code is:
*****
'Check if there are any forecasts less than one day old
If DCount("fldWeatherForecast", "tblWeatherForecasts", "now()-fldForecastDate < 1") < 1 Then
DoCmd.OpenForm "frmWeatherForecasts"
Exit Sub
End If
*****
* Now when the form opens it pops up a message asking me to, 'Enter Parameter Value', for, 'fldTargetArea'.
* It doesn't matter if I enter nothing or gobbledeegook or cancel, the form opens OK. But if I cancel it also tells me, 'The ApplyFilter action was cancelled'
* When I look back in the design of the form I find the filter is now set to, fldTargetArea = 'South East Wales'
* fldTargetArea is a field I use a lot but I am sure it isn't to be found anywhere on the form frmWeatherForecasts
* 'South East Wales', happens to be the value of fldTargetArea on the first record on table, tblTargetAreas
It seems DoCmd.OpenForm is picking up a filter value from somewhere but I can't see how.
Has anyone got any suggestions how I can force the form to open without trying to apply a filter?
Thank you very much for your help. Guy
* I have a database that generates flood warning messages
* The messages incorporate a weather forecast
* The weather forecasts are stored on a table, 'tblWeatherForecasts', as a memo, 'fldWeatherForecast'
* The other fields on the table are an auto number, 'fldForecastNumber', and a date stamp, 'fldForecastDate', set to now() when a new record is added.
* Form, 'frmWeatherForecasts', allows the user to add new weather forecasts
* Record source for the form is a query to ensure the latest record is shown first
SELECT tblWeatherForecasts.* FROM tblWeatherForecasts ORDER BY tblWeatherForecasts.fldForecastNumber DESC;
* No filter is set and Allow filters is set to No (I have tried Yes and that doesn't solve problem)
* An OnOpen event for the form checks if there is a recent weather forecast. The code is :
*****
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open
If DCount("fldWeatherForecast", "tblWeatherforecasts", "now()-fldForecastDate < 1") < 1 Then
MsgBox "Most recent weather forecast is more than 24 hours old. Copy todays forecast across from the Met Office e-mail or type in a summary situation.", , "No forecast!"
End If
'Error trapping code
Exit_Form_Open:
Exit Sub
Err_Form_Open:
MsgBox Err.Description, 0, "Form_Open!"
Resume Exit_Form_Open
End Sub
*****
So far, so good!
* When the user clicks a button on a form to generate a flood message the procedure that runs checks there is a recent weather forecast before proceeding
* The relevant bit of code is:
*****
'Check if there are any forecasts less than one day old
If DCount("fldWeatherForecast", "tblWeatherForecasts", "now()-fldForecastDate < 1") < 1 Then
DoCmd.OpenForm "frmWeatherForecasts"
Exit Sub
End If
*****
* Now when the form opens it pops up a message asking me to, 'Enter Parameter Value', for, 'fldTargetArea'.
* It doesn't matter if I enter nothing or gobbledeegook or cancel, the form opens OK. But if I cancel it also tells me, 'The ApplyFilter action was cancelled'
* When I look back in the design of the form I find the filter is now set to, fldTargetArea = 'South East Wales'
* fldTargetArea is a field I use a lot but I am sure it isn't to be found anywhere on the form frmWeatherForecasts
* 'South East Wales', happens to be the value of fldTargetArea on the first record on table, tblTargetAreas
It seems DoCmd.OpenForm is picking up a filter value from somewhere but I can't see how.
Has anyone got any suggestions how I can force the form to open without trying to apply a filter?
Thank you very much for your help. Guy