Results 1 to 5 of 5
  1. #1
    Historypaul is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    64

    Referencing a form field in a VBA statement

    I'm trying to simplify how this form works for future programming. I have a pull down to select the type, which also changes the subform so that it's formatted for the appropriate type. I have a second field that contains the subform name. I would like to refer to that subform name value in that text box in the "on load" event of the form so that I know it opens the correct subform each time. The "on load" event procedure I'm using is:

    [/code]


    Me.OpeningSashSubform.SourceObject = "&[Me].[SashForm]&"
    [code]

    In principle I think it works. I think my problem is just in my punctuation...

    I'd appreciate any help.

  2. #2
    alcapps is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jan 2012
    Posts
    292
    Me.OpeningSashSubform.SourceObject = " & [Me].[SashForm] & "

    make sure there are spaces..

    I don't understand your use of the form at this point.

    on open event you should have a default value. then when a combo box is selected the appropriate form would be
    re-queryed.
    maybe you can post an example form with basic data to help or at least an image of the form.


  3. #3
    Historypaul is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    64
    When I have spaces like you showed, I get a naming error as shown. I attached a picture trying to illustrate how I'm trying to make this form work.Click image for larger version. 

Name:	Naming Error.jpg 
Views:	5 
Size:	22.7 KB 
ID:	11113Click image for larger version. 

Name:	Form copy.jpg 
Views:	7 
Size:	116.5 KB 
ID:	11114

  4. #4
    Historypaul is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2012
    Posts
    64
    alcapps - it was the on open event default value I'm trying define based on a cell value.

    I decided to try doing it with a variable instead of trying to use the cell reference directly in the expression. It works fine now. Ended up looking like this.

    Code:
    Dim strSashForm As String
    strSashForm = Me.SashForm
    Me.OpeningSashSubform.SourceObject = strSashForm
    Thanks very much for being quick to jump in and offer to help!

  5. #5
    alcapps is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Jan 2012
    Posts
    292
    try using the on open event to use your code.

    on open event .. not load plus after update of your text box..sashform
    you don't need a string variable.

    on open event of the form..
    me.openingsashsubform.sourceObject = me.sashform
    me.openingsashsubform.requery

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

Similar Threads

  1. If statement in form field
    By Gabriel2012 in forum Forms
    Replies: 1
    Last Post: 01-29-2013, 05:03 PM
  2. Referencing Field Names
    By andy-29 in forum Access
    Replies: 6
    Last Post: 11-20-2012, 03:27 PM
  3. Referencing a query field
    By rcrobman in forum Queries
    Replies: 5
    Last Post: 04-29-2011, 04:06 PM
  4. If Statement to validate Field on a Form
    By ETCallHome in forum Forms
    Replies: 4
    Last Post: 04-05-2011, 05:22 PM
  5. Referencing A Form Field In A Report
    By CGM3 in forum Reports
    Replies: 5
    Last Post: 07-01-2010, 08:16 PM

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