Open a form without any data in it

Chunk

Registered User.
Local time
Today, 17:06
Joined
Oct 25, 2004
Messages
64
I want to open a form so it is blank.

I have looked through old posts, and the only way I can see to do it is using:

DoCmd.GoToRecord , , acNewRec

However, this is no good for me, as I dont want to allow data entry AND I have default values for one of the fields.

Is there a way to do this?

Thanks.
 
Its an enquiry form. The user makes a choice from a combo box AND THEN the data is shown on the form.

I dont want any data to be shown when it first loads up, until the user makes a choice in the combobox, because it just looks a lot neater.
 
Put code in the 'Form_BeforeInsert(Cancel As Integer)' event handler that checks the value of the combo. If the combo has not been set properly, reject the insert by setting 'Cancel = true'
 
SCREEN SHOT HERE

I dont think you understand what I mean. So I posted the screen shot. Basically if you choose something from either of those combo boxes at the top, the rest of the screen is loaded with data. When THIS form is first opened, I want it to be blank, I dont want it to show the first record in the table.

Is this possible?
 
Put your comboboxes in the form header.
Create a query which you combine to your comboboboxes by adding WHERE clauses in your query referring to your comboboxes.

Open your form in design view.
Select the tabpage Data.
Set the property Recordset Type to Snapshot

RV
 
The combo boxes at the top of the form should be unbound.

Move those combo boxes to the form header.

Your text boxes displaying the record fields should be in the detail section of the form.

Set the form Record Source property to "" (blank - no record source).

Set the form Navigation Buttons property to "No".

Set the form Auto Resize to "No". (edit - forgot this - sorry...)

Set the form Detail Section Visible property to "No".

In the After Update events for both combo boxes in the form header, place the following code:

Code:
Private Sub MyComboBox_AfterUpdate()

If Me.RecordSource = "" Then
    Me.RecordSource = "MyTableOrQuery"
    Me.Section(0).Visible = True
    Me.NavigationButtons = True
End If

End Sub

hth,
 
Last edited:
RV said:
Put your comboboxes in the form header.
Create a query which you combine to your comboboboxes by adding WHERE clauses in your query referring to your comboboxes.

Open your form in design view.
Select the tabpage Data.
Set the property Recordset Type to Snapshot

RV

I cant seem to get that to do anything.

The combo boxes at the top of the form should be unbound.

Move those combo boxes to the form header.

Your text boxes displaying the record fields should be in the detail section of the form.

Set the form Record Source property to "" (blank - no record source).

Set the form Navigation Buttons property to "No".

Set the form Auto Resize to "No". (edit - forgot this - sorry...)

Set the form Detail Section Visible property to "No".

In the After Update events for both combo boxes in the form header, place the following code:
Code:

Private Sub MyComboBox_AfterUpdate()

If Me.RecordSource = "" Then
Me.RecordSource = "MyTableOrQuery"
Me.Section(0).Visible = True
Me.NavigationButtons = True
End If

End Sub


hth,

It hides the whole data part of the form. I want it to be there, but I want the text boxes to be empty.
 
Then you'll need to set the control sources for your text boxes programatically as when you set the record source for the form.

Set the Visible property for all sections of the form to yes.

Set the form record source to "" (blank).

Then set the Control Source for each text box to "" (blank).

Then

If Me.RecordSource = "" Then
Me.RecordSource = "MyTableOrQuery"
Me.MyTextboxName1.Controlsource = "MyTableorQueryFieldName1"
Me.MyTextboxName2.Controlsource = "MyTableorQueryFieldName2"
etc...

End If

hth,
 
Last edited:
There are probably better ways to do this, but I have done this by accident. I assigned a filter with a value that couldn't be found an ended up with a totally blank form.

such as follows:

Code:
Public Sub OpenAsBlankForm()
   Me.Filter = "[SomeField]= 'Something that will never be found'"
   Me.FilterOn = True
End Sub

"[SomeField]" needs to be replaced with a field on you form, then search for something that will never be found in that field. When you want to go back to normal, turn off the filter with the following line:
Code:
Me.FilterOn=False

Hope this is helpful.
 

Users who are viewing this thread

Back
Top Bottom