Solved

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

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

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
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…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

691 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