Solved

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

Posted on 2014-11-26
4
248 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:
SimonAdept earned 500 total points
Comment Utility
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
Comment Utility
" 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
Comment Utility
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
Comment Utility
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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

743 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

17 Experts available now in Live!

Get 1:1 Help Now