I have a form which because of the operators using it is in datasheet view. The datasheet view changes to justified when I open it via the Switchboard. Is there any way to change this.
Or go behind the scenes and look at the code (or macro) that the switchboard is using to open the form and just change the arguments so that it opens in acViewDS.
Actually, I don't think you can do that, Bob! The switchboard is not really a form; you can't go into the code window, find the code for a given button and change it. That would be too easy; not the Micro$oft way at all! Your first idea was the right one, writing a function then calling it from the Switchboard.
The first problem is that, as Bob pointed out, a called form will only open in DataSheet View (regardless of which view is set in its Property Box) if explicitly told to do so!
DoCmd.OpenForm "YourFormName", acFormDS
The second problem is that the native Access Switchboard is very limited in how it handles tasks, which is why most people avoid them, using a custom form instead !
In the Database window got Modules
Click on New
Paste in this code, substituting the name of your form for YourFormName
Code:
Public Function OpenInDataSheetView()
DoCmd.OpenForm "YourFormName", acFormDS
End Function
When asked to name the module, use anything except OpenInDataSheetView. This would confuse the Access gnomes.
Now goto Tools - Database Utilities - Switchboard Manager
Hit Edit
Hit Edit again
Select the Switchboard Item that is currently opening your form
Thanks chaps for your assistance. I haven't tried your suggestions yet as I am writing this while eating my tea(spare arms and hands are very useful) at work, but I'll let you know how I get on
>>>the native Access Switchboard is very limited in how it handles tasks<<<
This is true, however you can go into the switchboard code and make a minor modification which then allows you to pass variables when you call code from the switchboard Interface.
There was a thread on this a while ago, and I intend doing a set of videos showing how useful the a built in switchboard is as soon as I get a minute.
That's right! I helped someone a while back who had accidentally deleted the Switchboard (not one of his own design) and was frantic to get it back. A number of people assured him that it had to be recreated from scratch, as you would with any other "form." Since the Switchboard Table wasn't deleted, I had him open a new database, create a new Switchboard, then export this Switchboard "frontend" to the original db. Problem solved!
I followed your instructions to the letter Missinglinq. In the Visual Basic Editor if I run Sub/UserForm the function works fine and opens my form but when I try on my Switchboard I get "There was an error executing the command". Where do I go from here?
I too had this same problem. I tried what linq said but it returned the same error and i'm not really sure how to work with modules so to (with some luck) fix it..
I created a new macro with the openform action.
The properties were set as:
Form Name = yourformname
View = datasheet
Data Mode = edit
Everything else left as default. For the button which opens my form, instead of using the module i set it to run the macro and it seems to work fine; opening the form in the desired datasheet view.
I think this is essentially the same as what linq has done with the module, but for some reason access is happier using the macro way.
----------
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.mspx
----------
Hmm, well unsuprisingly with the complexity of the other answers to this problem it doesn't work. When i first tried it i can honestly say it did, but now it doesn't ...
I'm even more confused, thanks though access i'll take a look at that.
Jon.
Edit: it's really quite strange, it now functions correctly again; opening the form in acViewDS. Maybe someone can tell me why it works sometimes?
the access switchboard is quite interesting to play around with
i do loads of things in mine as standard such as
a) test screen resolution, and advise accordingly
b) changed the standard "action not available" message to provide more information - ire explicitly report that a given form name doesn't exist
c) ask whether shutdown is really intended
d) include code to reconnect the backend
you can also modify the fields IN the switchboard items table, to add extra columns, which can be useful - eg can be used to provide an easy way of showing/hiding menu items for particular users/user groups
Now the module works, i don't really know why it didn't in the first place but after this little problem i think my project is finished, good news, now to test it - oh dear!