No records on form (crashy crashy) (1 Viewer)

homer2002

Registered User.
Local time
Today, 03:25
Joined
Aug 27, 2002
Messages
152
Ok i'm sure this one must be an old skool problem... but


I'm using Access 97.

If I try to open a form with "Additions disabled" ...
and there are no records in the recordsource ...
then the form just displays NOTHING.. ABSOLUTLY NOTHING

Is there a tried and tested method of opening forms like this so they dont crash and just display 0 (zero) records

Thanks in advance to anyone helpful :)

Homer The Not So Great !

_______________

There are 10 kinds of people in the world.. Those who understand binary, those who don't and those who can't count to 2! Guess which one I am :)
 

ghudson

Registered User.
Local time
Yesterday, 22:25
Joined
Jun 8, 2002
Messages
6,194
If you had searched the forum then you would have found a few variations of this code which will close the form if the record source contains no records. Put it in the forms OnOpen event.
Code:
Private Sub Form_Open(Cancel As Integer)
    
    If Me.RecordsetClone.RecordCount = 0 Then
        MsgBox "There are zero records in the data source!", vbInformation, "No Records Found"
        DoCmd.Close acForm, Me.name
    End If
    
End Sub
 

homer2002

Registered User.
Local time
Today, 03:25
Joined
Aug 27, 2002
Messages
152
Hi

cheers for the info.... but to be fair, I did look & found that code..and it didnt work

The problem is, everybody just closes the form if there are no records which is the exact opposite of what I need.

I need the form to stay open, set the recordsource to nothing and still display the form as normal but with no records.

At the moment I can either close the form instantly or use msgboxes and InputBoxes to get users Inputs and then have the form close itself. Nether of these are any good to me :-(

What I decided to do in the end was to Add code to a previous form that does all the checks and loads a different form if there are no records in the form that is causing the problems, this form then sets the correct record up for editing and then opens the problem form correctly.

I then found another way which worked for different senarios which was to Allow Additions, but to Cancel Any new records being created on BeforeInsert

.....A complete hack Job as it would be nice to have all the code within one form but I guess it works and thats what matters
 

ghudson

Registered User.
Local time
Yesterday, 22:25
Joined
Jun 8, 2002
Messages
6,194
Then I suggest that you set the forms RecordSource = "" to display the form but no records.
 

Users who are viewing this thread

Top Bottom