Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Access 2007 VBA Programmer's Reference ISBN: 978-0-470-04703-3
This is the forum to discuss the Wrox book Access 2007 VBA Programmer's Reference by Teresa Hennig, Rob Cooper, Geoffrey L. Griffith, Armen Stein; ISBN: 9780470047033
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Access 2007 VBA Programmer's Reference ISBN: 978-0-470-04703-3 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 April 17th, 2010, 11:17 AM
Registered User
 
Join Date: Apr 2010
Location: CT
Posts: 10
Thanks: 1
Thanked 1 Time in 1 Post
Question Move form from table field into variable to run form

Hi Everyone!
I am having trouble building custom menus and specifically ...

I need to take be able to open a form or a report using a variable form/report name that is coming from a table.

First read the file containing the menu options sequentially.
Move the menu description from field ItemText field to the caption property
Move the form name from field Arguement into a variable so that when the form runs the user can click on the menu button and run the variable form.

Code:
Private Sub btn1_Click()
     ' DoCmd.OpenForm "frmAddCustomer"  (This works fine - opens the form)
     ' But here I want to open the form from a variable name loaded below.
DoCmd.OpenForm pgm1
End Sub


Private Sub Form_Load()
Dim conn1 As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim strSQL As String
    Dim pgm1 As Form
    Dim pgm2 As String
        
  ' Format the strSQL string with the fields that I want and the user selected search field as the customer name to search for.

    strSQL = "SELECT * FROM MenuItems WHERE MenuID=3 Order By ItemNumber"
    
  ' Start the connection and process the SQL query on the recordset.
    Set conn1 = CurrentProject.Connection    
    Set rs = New ADODB.Recordset

    rs.Open strSQL, conn1
    rs.MoveFirst   ' new code added
    btn1.Caption = rs![ItemText]  'THIS PART WORKS FINE
    pgm1 = rs![Argument]           ' THIS WILL NOT WORK AT ALL
    btn2.Caption = rs![ItemText]
    pgm2 = rs![Argument]

End Sub

'I dont know how to put a form name into a variable and then use that variable in a Do.Cmd statement.
If anyone knows how to do this I would be very grateful. I know how to find out if a specific form is open or not, but do not have any idea how to move the field from the table into a variable and then use that in the Do.Cmd statement. Is there some special way to specify a variable as a form? Without knowing what the keyword is, it is almost impossible to look this up or find it on the Internet.

Thanks Everyone!
Ann

Last edited by AnninCT; April 17th, 2010 at 11:19 AM. Reason: field name was incorrect in text and was confusing
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
How do you move the mouse outside the form and to move diagonally? fangzhien Visual Studio 2005 0 July 28th, 2009 10:06 PM
help with passing a variable from a form field via url Igor Astakhov BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 2 March 10th, 2009 02:00 PM
Move cursor to beginning of field in form Odeh Naber Access 3 June 5th, 2007 04:21 PM
Select a field on a form, based on variable JAnthony Access VBA 2 April 17th, 2006 11:16 AM
How Do I Close a Form When I Move to Another Form. flyingfox VB.NET 2002/2003 Basics 3 December 29th, 2003 07:56 AM



All times are GMT -4. The time now is 03:48 PM.


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