Solved

Display Form when called from a menu with criteria when no matching data.

Posted on 2014-11-26
4
257 Views
Last Modified: 2014-11-27
In MS Access I have a Form being displayed from a Menu.  If the Form Dataset doesn't have any data it, it displays a blank form.

How do I display the form in say 'Add' Mode?

I have a Button on the Form that I want to be able to click to execute an Event Procedure that loads the Dataset from an MS Excel File.
0
Comment
Question by:Bob_Collison
4 Comments
 
LVL 18

Accepted Solution

by:
Simon earned 500 total points
ID: 40467400
Set the form property [allow additions] to true. You can either set the form to always allow additions by setting it as a property of the form while in design mode, or dynamically during the Form_Open event, depending on the state of the underlying datasource.

You can do this in the Form_Open event
Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
Me.AllowAdditions = True
Else
Me.AllowAdditions = False
End if
End Sub

Open in new window


Or, you could cancel the Form_Open event and pop up a different form that just contains your button.
Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
Cancel = True
DoCmd.OpenForm "ButtonForm"
End If
End Sub

Open in new window


Your button form can then load the data to your table from Excel and open your original form with the new data loaded.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 40467785
" have a Button on the Form that I want to be able to click to execute an Event Procedure that loads the Dataset from an MS Excel File. "

...Then why open a "blank" form at all...?

You can select the datasource before you open the form, then just open the form with the data displayed.

Not sure why the extra steps of opening the form empty, seting it to "add mode" then selecting a datasource, ...then displaying all the data, ... is needed...?
(BTW "add Mode" is only needed if you are "manually" adding records, ...in your case you are simply picking a recordsource, ...so in this case, "add mode" is not really needed as far as I can tell)

In other words, ...can you take a step back and explain what your ultimate goal here is, ...in case there is a simpler solution...?
;-)

JeffCachman
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 40468458
You could change the form to a main form holding a subform.

The main form will be unbound (no recordsource) and have the button to load the dataset into the subform.
The subform will be bound to your current data source and could be a simple DataSheetView form.

When no records, the subform will be blank (empty) but the main form will live.

/gustav
0
 

Author Closing Comment

by:Bob_Collison
ID: 40469251
This solution (first part) I believe is the best as it directly addresses my original requirement.
However thanks for the other suggestions.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question