Access2003 Form/Query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wquatan
    New Member
    • Oct 2007
    • 48

    #1

    Access2003 Form/Query

    Hi,

    I have a form, bound to a query.
    None of the queryfields are on the form as the form is only there for navigation.

    In an form.event (OnCurrent) I want to use (in VBA) the queryfields, but ..... how do I reference to the QueryFields ?

    Thx
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You reference a field by typing the field name.

    Comment

    • MMcCarthy
      Recognized Expert MVP
      • Aug 2006
      • 14387

      #3
      Originally posted by wquatan
      Hi,

      I have a form, bound to a query.
      None of the queryfields are on the form as the form is only there for navigation.

      In an form.event (OnCurrent) I want to use (in VBA) the queryfields, but ..... how do I reference to the QueryFields ?

      Thx
      Put the query fields on the form but set them to invisible if you don't want the user to see them.

      Comment

      • wquatan
        New Member
        • Oct 2007
        • 48

        #4
        Originally posted by mmccarthy
        Put the query fields on the form but set them to invisible if you don't want the user to see them.
        That's what I wanted to avoid.
        I thought I would have been possible to use sort of Me!captionname. fieldname referencing instead of Me!fieldname

        Comment

        • MMcCarthy
          Recognized Expert MVP
          • Aug 2006
          • 14387

          #5
          Originally posted by wquatan
          That's what I wanted to avoid.
          I thought I would have been possible to use sort of Me!captionname. fieldname referencing instead of Me!fieldname
          If you want to refer to values in fields in the query bound to the form then those fields have to be in controls on the form.

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            Originally posted by mmccarthy
            If you want to refer to values in fields in the query bound to the form then those fields have to be in controls on the form.
            That can't be right, I know I've been able to reference fields that have no corresponding control on my form but are in my control source.

            Comment

            • wquatan
              New Member
              • Oct 2007
              • 48

              #7
              Originally posted by Rabbit
              That can't be right, I know I've been able to reference fields that have no corresponding control on my form but are in my control source.
              That's exactly what I want to do.
              Can you remember how-to ?
              Would be great to have a syntax-sample :-)

              Thx

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32669

                #8
                Originally posted by Rabbit
                That can't be right, I know I've been able to reference fields that have no corresponding control on my form but are in my control source.
                That would certainly be interesting Rabbit. I too am of the opinion that you reference an item by Me.ControlName rather than Me.FieldName.
                It wouldn't be the first time you've confounded us with some extra clever stuff, but I wait to be convinced on this one.

                Comment

                • missinglinq
                  Recognized Expert Specialist
                  • Nov 2006
                  • 3533

                  #9
                  And the winner is......Br'er Rabbit! Yes, you certainly can reference a field in the underlying table/query that isn't bound to a control on the form! The syntax is simply

                  Me.FieldName
                  !

                  Welcome to TheScripts, wquatan!

                  Linq ;0)>

                  Comment

                  • MMcCarthy
                    Recognized Expert MVP
                    • Aug 2006
                    • 14387

                    #10
                    Originally posted by missinglinq
                    And the winner is......Br'er Rabbit! Yes, you certainly can reference a field in the underlying table/query that isn't bound to a control on the form! The syntax is simply

                    Me.FieldName
                    !

                    Welcome to TheScripts, wquatan!

                    Linq ;0)>
                    Nice one Rabbit and Linq.

                    I have honestly never tried to do that so the issue never came up. That's what fascinates me about Access. How much we don't know :D

                    Comment

                    • FishVal
                      Recognized Expert Specialist
                      • Jun 2007
                      • 2656

                      #11
                      Its quite an interesting thing.

                      Seems that Item property of Form.Controls collection is quite intelligent to return recordset field when no control has the name passed as argument.

                      Example.
                      [SomeForm] has a RecordSource but no control.

                      ? Forms!SomeForm. Controls.Count
                      0

                      ? Forms!SomeForm. Controls!SomeFi eld
                      <FieldValue>

                      ? TypeName(Forms! SomeForm.Contro ls!SomeField)
                      AccessField
                      that is hidden class in Access library

                      And even more interesting.
                      Access creates property SomeField in Form_SomeForm class quite intelligently.
                      If [SomeForm] has a control bound to [SomeField], then the property is declared to return the control object. Otherwise it is declared to return AccessField object. Anyone can easily check this in Object Browser.

                      Summary.
                      • if a form bound to query/table doesn't have a control with the name same as of recordset field, then references like
                        Me.SomeField
                        and
                        Me!SomeField
                        will return AccessField object
                      • if a form bound to query/table has a control with the name same as of recordset field, then references like
                        Me.SomeField
                        and
                        Me!SomeField
                        will return the control object

                      Comment

                      • MMcCarthy
                        Recognized Expert MVP
                        • Aug 2006
                        • 14387

                        #12
                        It's interesting stuff. Typical of Access to do something really clever and forget to tell you about it. :)

                        Comment

                        • MMcCarthy
                          Recognized Expert MVP
                          • Aug 2006
                          • 14387

                          #13
                          Originally posted by mmccarthy
                          It's interesting stuff. Typical of Access to do something really clever and forget to tell you about it. :)
                          By the way, if anyone would like to do an article on this that would be even better.

                          Comment

                          • NeoPa
                            Recognized Expert Moderator MVP
                            • Oct 2006
                            • 32669

                            #14
                            Sounds like I was simply wrong on this one then :(
                            Never mind. It's something I should have a play with and know for the future. Thanks for the responses people :)

                            Comment

                            Working...