?
Solved

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

Posted on 2014-11-26
4
Medium Priority
?
273 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 18

Accepted Solution

by:
Simon earned 2000 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 51

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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

765 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