A command button to preview the recordset of a form

  • Thread starter L Walsh via AccessMonster.com
  • Start date
L

L Walsh via AccessMonster.com

I have a form whose recordsource is a query on table tblMytable. The form has
some command buttons. One runs an event procedure to process all records in
the form's recordset. Another is a "preview" of all the records that will be
processed. The preview button runs an OpenQuery macro, that runs the same
query that is the recordsource of the form. It opens it in readonly mode.

When I click on the preview button I get the message "The table tblMytable is
already opened exclusively by another user, or it is already open through the
user interface and cannot be manipulated programmatically"

Is running the query from a command button on the form the wrong way to
preview the records in the form's recordset? How should I be doing this?

Tia for your help.
LW
 
J

John Vinson

Is running the query from a command button on the form the wrong way to
preview the records in the form's recordset?

Well said:
How should I be doing this?

Use the Form's Load event and check the recordsetclone's recordcount:

Private Sub Form_Load(Cancel as Integer)
If Me.RecordsetClone.Recordcount = 0 Then
Cancel = True
MsgBox "No records found matching these criteria", _
vbOKOnly + vbExclamation
End If
End Sub

I see no point in "previewing" the contents of the records, though;
forms are designed to view records (and edit them), and query
datasheets are best left for debugging!

John W. Vinson[MVP]
 

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