BLANK FORM BASED ON A QUERY

  • Thread starter Thread starter dan.cawthorne
  • Start date Start date
D

dan.cawthorne

I Have Created a Dialog Form With a Button That Opens Another form,
the Form That Gets Opened By The Dialog form is Based On a Query, and
The Creteria Is Set To A value Inputed on the Dialog Form,

Which Works Great When I Have Results Turned Up,

If No Results The Form is Blank,

Is Their A Code i can put in the CLick Event of the Dialog form that
Opens the form, if there are no Results Wont Allow me to Open the
form. and a Message..

Ive Tried The Following

DoCmd.OpenForm "Project_Results_ByRecievedDate"

If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "No records"
Me.FilterOn = False
End If

End Sub

And I Get a RecordsetClone Error Any Help
 
You can cancel the opening of the target form if it has no records by using
the form's Open event procedure:
Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
Cancel = True
MsgBox "No results to show in form " & Me.Name
End If
End Sub

In the routine that uses the OpenForm, you will need to use an error handler
to handle 2501 (the message that lets your code know the form did not open.)
 
Hi Dan

The recordset isn't available until the form is opened.

Before opening the form you could assign the query to a recordset, test if
there are records, then close the recordset and then open the form if there
were records.

Or...

Open the form anyway and in its open event use something like...

With Me.RecordsetClone
If .BOF and .EOF Then
MsgBox "No Records"
DoCmd.Close acForm, Me.Name, acSaveNo
End If
End With

Note: I use .BOF and .EOF to test if there are records and not RecordCount
because, depending on the recordset type, RecordCount won't be set until the
last record has been read.

Hope this helps

Andy Hull
 
Hi Dan

The recordset isn't available until the form is opened.

Before opening the form you could assign the query to a recordset, test if
there are records, then close the recordset and then open the form if there
were records.

Or...

Open the form anyway and in its open event use something like...

With Me.RecordsetClone
If .BOF and .EOF Then
MsgBox "No Records"
DoCmd.Close acForm, Me.Name, acSaveNo
End If
End With

Note: I use .BOF and .EOF to test if there are records and not RecordCount
because, depending on the recordset type, RecordCount won't be set until the
last record has been read.

Hope this helps

Andy Hull













- Show quoted text -

Thank You Very Much Both of You, Im Spoilt for Choice to Day,
 
Back
Top