Results 1 to 7 of 7
  1. #1
    degras is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    72

    Referencing properties of a modal form in VBA

    How do I reference properties of a modal form in VBA.
    e.g. I have a modal form called "DatesForm" and I invoke it as follows:
    DoCmd.OpenForm "DatesForm"
    How do I reference the modal result and the fields on the form (what syntax do I use) ?


    I want to set the value of a text box called CompanyText, on the form.

  2. #2
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,044
    Hi,

    if the form is opened you can access it through the Forms collection, for example print the forms name in the immediate window:

    Debug.Print Forms("DatesForm").Name

    Success
    NG

  3. #3
    degras is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    72
    Quote Originally Posted by NoellaG View Post
    Hi,

    if the form is opened you can access it through the Forms collection, for example print the forms name in the immediate window:

    Debug.Print Forms("DatesForm").Name

    Success
    NG
    I tried adding this code to my application and nothing happened. Where is the immediate window? How does this help me achieve what I originally asked?

  4. #4
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,044
    Hi,

    you asked a way to access the form and you can do this through the forms collection. As a surplus I gave you an example how to use the forms collection, it's up to you to use this in the way you need.

    As I don't know how your app works and what exactly you're trying to achieve, I can't write the code for you. And even if I could, where would be the fun for you...

    You can open the immediate window through the view -> Immediate Window in the toolbar of the VBA window. And the debug object does just what it tells: it helps with debugging and one method there is printing the results of codelines in the immediate window.

    have fun with the coding
    NG

  5. #5
    degras is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    72
    I tried to set the value of a text box on the modal DatesForm using the following:
    DoCmd.OpenForm "DatesForm", , , "CompanyNameText=" & Me.Company
    ... it did not show any error when the code was run, but the CompanyNameText was blank. What am I doing wrong?

  6. #6
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,044
    Try:

    Code:
    DoCmd.OpenForm "DatesForm"
    Forms("DatesForm").CompanyText = strMyValue
    where strValue has to be replaced by the variable that contains the actual value

  7. #7
    degras is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    72
    Quote Originally Posted by NoellaG View Post
    Try:

    Code:
    DoCmd.OpenForm "DatesForm"
    Forms("DatesForm").CompanyText = strMyValue
    where strValue has to be replaced by the variable that contains the actual value
    Thanks that worked fine.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Referencing a form in a subform
    By 161 in forum Forms
    Replies: 3
    Last Post: 01-24-2011, 03:58 PM
  2. Form Properties
    By mwabbe in forum Forms
    Replies: 3
    Last Post: 09-23-2010, 10:14 AM
  3. Referencing split form data / filter
    By stephenaa5 in forum Programming
    Replies: 2
    Last Post: 09-14-2010, 08:48 AM
  4. Referencing A Form Field In A Report
    By CGM3 in forum Reports
    Replies: 5
    Last Post: 07-01-2010, 08:16 PM
  5. Displaying Query Properties in a Form
    By Bjar in forum Programming
    Replies: 1
    Last Post: 07-16-2008, 07:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums