473,385 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How can I open a form using a combo box in the switchboard?

4
Hi guys,
I'm fairly new to access, with the help of this site and google I've managed to find my way around (even dabbling with some VB too) but there's something that's got me stuck.
I've got my DB working great, it's got the standard switchboard generated via the switchboard manager. I've got a load of forms and reports on there so I'd like to use a combo box to open up my forms rather than the buttons. For example I've got five forms I'd like to open up in add mode (one combo box) and another five forms I'd like to open in edit mode (second combo box). I'm sure this can be done but I'm struggling to find anything out there that can help me out... any ideas?
Many thanks,
Matt
Jul 26 '07 #1
7 4747
Mattic
4
Noone got any ideas?
Jul 26 '07 #2
missinglinq
3,532 Expert 2GB
Setting the RowSource of a combobox to retrieve the names of all the forms in a database is easy, but opening some in one mode and some in others is a little bit more compicated.

Method A - Using 2 Comboboxes
You'd have to rename your forms, placing a a prefix before each name, i.e. edForm1 for a form you want to open in Edit mode and adForm2 for a form you want to open in Add mode. One combobox would retrieve all forms with the ed prefix and the other would retrieve all forms with the ad prefix. Then in the AfterUpdate event of the combobox the selected form would be opened in the appropriate mode.

Method B-Using 1 Combobox
The combobox would retrieve the names of all forms. In the AfterUpdate event of the combobox you would use a Select Case construct to tell Access which mode to open a particular form in.

There are some drawbacks to both methods. Method A requires that you stick to a strict naming convention in order that the correct forms are retrieved by the appropriate combobox. If you have forms in your database that you don't want retrieved by either combobox, you'd have to be sure not to name them with anything starting with either ed or ad. The SQL statement behind your comboboxes looks at the first two letters of the form's name in deciding whether or not to retrieve it. The advantage to this method is that if you later create new forms, you can include them in one or the other combobox by the simple virtue of the name you assign to them.

The drawback to Method B is that you would have to do the coding for the Select Case statement when you first set this up, and modify it each time you add a new form, to tell Access how to open the forms.

Think about which approach you'd prefer to use and let me know, and I'll post the relevant code for you..

Welcome to TheScripts!

Linq ;0)>
Jul 26 '07 #3
Mattic
4
Thanks Linq it's good to be here :)
Method A sounds like the best for me - thanks again!
Matt
Jul 27 '07 #4
missinglinq
3,532 Expert 2GB
From my previous post:
"You'd have to rename your forms, placing a prefix before each name, i.e. edForm1 for a form you want to open in Edit mode and adForm2 for a form you want to open in Add mode. One combobox would retrieve all forms with the ed prefix and the other would retrieve all forms with the ad prefix.

While this doesn’t involve a lot of code, it does involve a bit of setting up of of properties that can be daunting for a newbie, and so I’m going to give you step-by-step instructions on this.

Place two comboboxes on your form. When the Wizard comes up click on “Cancel”

For each combobox

Right click on the combobox
Click on Properties
Click on Other
Enter Names for Combobox (SelectFormsEdit and SelectFormsAdd respectively)
Click on Data
Set Row Source Type to Tables/Query
Set the Row Source by copying and pasting the SQL statements below

Row Source for Forms in Edit Mode

SELECT [MSysObjects].[Name] FROM MsysObjects WHERE (Left$([Name],2) = "ed") And ([MSysObjects].[Type])=-32768 ORDER BY [MSysObjects].[Name];

Row Source for Forms in Add Mode

SELECT [MSysObjects].[Name] FROM MsysObjects WHERE (Left$([Name],2) = "ad") And ([MSysObjects].[Type])=-32768 ORDER BY [MSysObjects].[Name];

************************************************** *****
Right click on the combobox
Click on Properties
Click on Events
Click to the right of the AfterUpdateProperty box
Click on Code Builder
For the appropriate Comboboxes enter the code below

DoCmd.OpenForm SelectFormsAdd, , , , acFormAdd

DoCmd.OpenForm SelectFormsEdit, , , , acFormEdit

so that the code looks like this

Expand|Select|Wrap|Line Numbers
  1. Private Sub SelectFormsAdd_AfterUpdate()
  2.  DoCmd.OpenForm SelectFormsAdd, , , , acFormAdd
  3. End Sub
  4.  
Expand|Select|Wrap|Line Numbers
  1. Private Sub SelectFormsEdit_AfterUpdate()
  2.  DoCmd.OpenForm SelectFormsEdit, , , , acFormEdit
  3. End Sub
Good Luck!

Linq ;0)>
Jul 27 '07 #5
Mattic
4
Linq you star! It worked great thanks for your time :) I've now got a great looking switchboard!

The only thing I needed to was allow edits on the form itself (below) and it all worked great!

"The form that the wizard creates sets the "Allow Edits" property to "No." This setting effectively disallows any selection from combo boxes. All you need to do is open the form in Design View, go to the Properties list for the form itself, and change the Allow Edits property to "Yes." Save and close the form. You will now be able to make a selection in the combo box."
http://www.accessmvp.com/JConrad/accessjunkie/switchboardfaq.html#combobox

Thanks again!
Jul 30 '07 #6
missinglinq
3,532 Expert 2GB
Didn't realize that! Most of us here don't use the Switchboard Manager, but rather create our own using a form. Forms are much more flexible! It makes sense, though, because in the normal scheme of things you wouldn't be editing records (or doing abything else to them) on a Switchboard. This behaviour is restricted to the Switchboard Wizard; the Form Wizard sets AllowEdits - AllowDeletions - AllowAdditions all to Yes.

Glad you got everything working! It was fun working on this for you!

Linq ;0)>
Jul 30 '07 #7
mb60
37 32bit
Sir
The code to open forms in combo box worked very nicely !
Interface of my database changed like a beautiful face
thank you
Jan 21 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Martin Dennett | last post by:
Hi I'm new to this group so go easy on me! I currently use a database that has had one constant niggle for a while and I was wondering if anybody can help sort it out. From an opening screen...
4
by: Terry | last post by:
I have created a Main Switchboard in Access 2000 and it has a button which opens a Form. I have set the form Properties Default View to Datasheet and this always opens in datasheet view. When I...
1
by: tdmailbox | last post by:
I am looking to set up a switchboard that doesnt have new forms open as pop open in new windows like they do as the default I am looking to make my own switchboard where I have the list of forms...
2
by: Miguel | last post by:
I have reviewed the many postings on this topic and understand the principle, but am not sure where in my case to apply trapping an error. I have created a form to supply parameters to a report. I...
3
by: Cagey | last post by:
What I'm trying for: If this selection or if click on selection (highlighted line choice/ which ever selection change) w/in query's combo dropdown list box (on Switchboard), then Open in...
9
by: mtgrizzly52 | last post by:
Hi all, I've looked for an answer for this in lots of books, online in several discussion groups and have not found the answer which I feel may be very simple. What I want to do is have a...
6
by: Markus_989 | last post by:
I have a LOANS table that has a list of loan details for different borrowers. I have a main switchboard with a LOANSELECT combo box (that displays a list of borrower last names and loan numbers)....
1
by: Kevin Welch | last post by:
Looking for some expert help here. Caveat: I do not know SQL, and I've built a database basically by trial and error (unfortunately, I don't have much time to learn Access as I would want). ...
4
by: Nour469 | last post by:
Hello, I need simple help! I have a form with a field (DrsName) which is a combo box that looks up values in another table (Drs List). When I come across a name that is not in the list, I need...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.