Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 5th, 2004, 11:34 AM
Registered User
 
Join Date: May 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default instantiate a form object by its name in MS Access

Hi,
I am trying to build a wizard in ms access. The wizard wil have several forms which load as subform one by one in the main parent form.
Any way, before moving to the next form I need to pass the variables from the previus form.
I am trying to write a resuable module so that I can apply to other sections of my application (other wise I could have used public variables).
In order to do so I want to loop through the controls of each form (before loading the next one) and add the variables to a collection object for further retrival on the next form.
The problem I am facing is that in order to write a function or a sub that will get the form name and add all its controls to a collection I have to instantiate a form by its name. I am trying to use the below code but I get a Type mismatch error.
Public Sub SaveFormData(strFormName As String)

   Dim ctl As Control
   Dim key As String
   Dim value As String
   Dim f As New Form


   Set f = CurrentProject.AllForms(strFormName)

   For Each ctl In f.Controls

       If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
           key = ctl.Name
           value = ctl

           NewWizardCol.Add value, key
       End If

   Next ctl

End Sub

if I use the below code to instantiate the form every thing works fine:
set f=Form_frmProductDupCheck


Any ideas how I can instantiate the form using its name. (I'm working in MS Access 2000)

Thanks

Reply With Quote
  #2 (permalink)  
Old May 6th, 2004, 03:44 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Oxford, , United Kingdom.
Posts: 120
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Could you not just pass a reference to the form into the sub?

i.e. instead of
Code:
Public Sub SaveFormData(strFormName As String)
use
Code:
Public Sub SaveFormData(frmFormName As Form)

Brian Skelton
Braxis Computer Services Ltd.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
MS Access Form Bind With OO4O MTForm Access VBA 4 February 27th, 2008 03:29 PM
How can show graphs in MS Access form ayazhoda Access VBA 20 April 23rd, 2007 06:50 AM
ms access form as criteria on sql server backend ottos13 Access 1 September 13th, 2006 12:14 PM
problem using ADO to open form in MS Access apike VBScript 3 May 2nd, 2006 06:25 AM
Microsoft Web Browser used in MS Access Form jeff1804 Access 8 December 9th, 2005 06:17 PM



All times are GMT -4. The time now is 02:25 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.