Above Header LeaderBoard <body> <!--Google Navigation Bar--> <script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener("load", function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <iframe src="http://www.blogger.com/navbar.g?targetBlogID=34083602&amp;blogName=LEARN+MS-ACCESS+TIPS+AND+TRICKS&amp;publishMode=PUBLISH_MODE_FTP&amp;navbarType=BLUE&amp;layoutType=CLASSIC&amp;searchRoot=http%3A%2F%2Fblogsearch.google.com%2F&amp;blogLocale=en_US&amp;homepageUrl=http%3A%2F%2Fwww.msaccesstips.com%2F" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" height="30px" width="100%" id="navbar-iframe" allowtransparency="true" title="Blogger Navigation and Search"></iframe> <div></div>
Header Right Columns
www.msaccesstips.com

LEARN MS-ACCESS TIPS AND TRICKS

Home

LEARN MS-ACCESS TIPS AND TRICKS

↑ Grab this Headline Animator

Your Ad Here
Saturday, May 19, 2007

Opening Access Forms

Using the same method that we have seen in the Closing Forms topic, we can create Command Buttons on the Control Screen and link the Forms to each Command Button by setting the Form Name to the Hyperlink SubAddress Property. This is the easiest method to open forms from a central point, when you have several forms in your Application. But the problem with this method is that you may end up with several command buttons on your Control Screen.

We will look into different methods to organize and open the Forms from the Control Screen. We will look into one of them here and we need little preparation for this method.
First of all, create a Table with the following Fields:
SRLField NameField TypeField Size
1.IDNumberInteger
2.DESCText35 Characters
3.FORMText20 Characters
4.MACROText20 Characters
5.TYPENumberInteger

and save it with the name: DataFiles.

An Image of a Table with sample data filled in is given below:

Table for Listbox (click)

Fill the table with your data files’ list for which you already have Forms designed for them with a Serial Number and Description in the ID & Desc fields and the Form Name for each Table in the Form Field. Fill the Type field with zero (0), for the time being and we will see the use of that information soon.

Now create a List Box on the Control Screen and select only ID & Desc fields from our DataFiles table as source data for the list box.

When you open your Control Screen you will see the serial number and description of your data files in the List Box. A Sample Screen with Listbox is given below for reference.





Listbox on the Control Screen (Click)



Now, go back to the design view of the Control Screen (if you have turned on the Form View earlier) and click on the ListBox and display the Property Sheet (View- ->Properties…). Change the Name Property to Dat1.

Display the VB Module (click on the Module Tab of your Database and click on the New option on the database window, which will open a new Global Module. Copy and Paste the following Code in that Module and save it.


Public Function FormOpen(ByVal FileName As String, _
ByVal ID As Integer) As Boolean
Dim vartyp As Variant, varFormName As Variant
Dim varMacName As Variant
Dim Criteria As String

On Error GoTo FormOpen_Err

FormOpen = False

Criteria = "ID = " & Format(ID)

vartyp = DLookup("Type", FileName, Criteria)

If vartyp = 0 Then
varFormName = DLookup("Form", FileName, Criteria)
If IsNull(varFormName) = False Then
DoCmd.OpenForm varFormName, acNormal
End If
ElseIf vartyp = 1 Then
varMacName = DLookup("Macro", FileName, Criteria)
If IsNull(varMacName) = False Then
DoCmd.RunMacro varMacName
End If
End If

FormOpen = True

FormOpen_Exit:
Exit Function

FormOpen_Err:
MsgBox Err.Description, , "FormOpen"
FormOpen = False
Resume FormOpen_Exit
End Function



Now, we have to write a line of code for the On DblClick Event for the listbox. Go back to the listbox design view and display its Properties Sheet. Click on the On Dbl Click property and select [Event Procedure] from the combobox and click on the build () button to open up the form’s code module.

You will find an empty On Dbl Click Event Procedure with its starting line Private Sub Dat1_DblClick(Cancel As Integer) and End Sub lines. Complete it by inserting a line of code between these lines as shown below without making typing mistakes:

Private Sub Dat1_DblClick(Cancel As Integer)

FormOpen "DataFiles", Me![Dat1]

End Sub


If you are not sure, highlight the middle line code above, copy and paste it correctly between the code lines appearing in your form module. It is important that you name the listbox as Dat1 and it is appearing in the code. The list box source data table name is in quotes and a comma is separating both the parameters to the FormOpen function. If you have used any of this objects name differently you have to correct them here.

Now, close the Form’s Code Module and save the Form. It is time to test our project. Before testing, check the accuracy of the Form Names that you have filled in, in the Form field of the DataFiles Table.

Open the Control Form. Double-Click on any line in the listbox and you must see your Form corresponding to that item you have double-clicked opens immediately.

If you end up with some errors then double-check the Name of the listbox, the source data table name, the Form Name in the Form field of the DataFiles Table and ensure that zero is filled in the Type field as well. The serial numbers in the DataFiles Table must be continuous numbers. It is convenient if you give shorter names to your Forms so that you don’t make mistakes while using their names.

How it works:

When you double-click on the listbox the sequence number corresponding to the item, and the Listbox Source Data Table’s Name are passed to the function FormOpen(). The FormOpen() function picks the Type value of the item double-clicked and checks its status and executes.

If the Type Value is

Empty - Ignores the Double-Click action (nothing happens).

0 - picks the Form’s Name from the Form field of the DataFiles Table and opens it.

1 - the program looks for the Value in the Macro Field of the DataFiles Table and runs that macro.

This is useful if you want to open a table in Read only mode, or to open a form after running a series of Queries to create an output table/Query linked to a Form which expects different results every time etc. by writing a macro and putting it’s name in the Macro Field.

This method can be used for Reports also. If you design more Forms/Reports later all you need to do is to add that item in the Listbox source table and the double-click action takes care of the rest.

Next we will see how to use the Hyperlink method in a listbox like design.

Click Next to see use of Hyperlinks in Listbox

Labels:

0 Comments:

Post a Comment

Note:Comments subject to Review by Blog Author before displaying.

Links to this post:

Create a Link

<< Home

Page Footer

Creative Commons License
Learn MS-Access Tips and Tricks by msaccesstips.com is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 2.5 India License.



This Page is best viewed with 1280 x 1024 Resolution

Sidebar Left
   FEATURED LINKS
SITEMAP
Command Button Animation
3D Headings on Forms
MsgBox & Office Assistant
Reminder Ticker
MS-Access & E-Mails
Automated E-Mail Alerts
MsgBox with Options Menu
Colorful Command Buttons
Configure Lotus Notes
Alerts through Network
Running this site has become a costly affair as the revenue from Ads is not sufficient to support it. If you find these pages informative & useful and would like to extend a helping hand, then please do it here.





Link Back to us with this Button

Learn MS-Access

Copy and Paste this HTML Code in your Webpage


Add to Technorati Favorites

Programming Blogs - Blog Catalog Blog Directory
Powered by FeedBurner
Add to Google

Software
Computers blogs
TopOfBlogs



AddMe - Search Engine Optimization Submit Your Site Free!
Go BlogZ Ave Blogs
eBlogzilla Changing LINKS
LS Blogs Blogarama
blog search directory BlogUniverse
Find Blogs in Directory RSS Directory
blogskinny.com ShowcaseBlogs.com
Amfibi

Search Engine Optimization and SEO Tools
Dmegs Web Directory Takeaway for Sale Businesses For Sale
Free Submission Directory Free site submission

Free Listing
 

Sidebar Right Top



Free Page Rank Checker

AddThis Social Bookmark Button

Enter your email address:

Delivered by FeedBurner



Top Blogs

Microsoft Access is the Jewell among MS-Office suite of Applications. Its Security features are excellent and works fine in Network environment. MS-Access can link/upload data from any Data Source. Applications that you design should be user-friendly and visually pleasing too. Here I would like to share my experience in Microsoft Access Programming with you and I am sure that you will find them interesting too.

My Photo
Name: Ramachandran Pillai
Location: Ruwi, Oman


If you need a Demo of any of the Topic explained here, send me an E-mail to: aprpillai@msaccesstips.com
with the Topic Description, I shall try to send a sample database to you.


Sidebar Right Top

Access Tips | Email | Reports | Report Tricks | Graphs | Forms | Menus | Animation | Security | Internet | How TOs | Linking | Query | Progress Meter | Alerts | Process Tips | Access Functions |





Site Designed by:www.msaccesstips.com