Solved

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

Posted on 2014-11-26
4
253 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

863 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

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now