Form unbound text box update with query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pbabin
    New Member
    • Jul 2014
    • 5

    Form unbound text box update with query

    I have a query to add a record to table which is fine. What I am trying to accomplish is to one
    1>Find the highest value assigned to the part # in the same table. This was done with another extra query.
    a.QryMaxAGL
    Code:
    SELECT Max([TAGLserial].[AGLID]) AS AGLmax FROM TAGLserial;
    2> Create a text box (unbound) in the form that show the value of the AGLmax + 1
    3> Assign this value to one of the field in the table when the user add a new record.
    In summary, I have used the following, but I can’t get it to work.
    Code:
    	Me.text101=  SELECT Max([TAGLserial].[AGLID]) AS AGLmax FROM TAGLserial;
    Property sheet,
    control source = SELECT Max([TAGLserial].[AGLID]) AS AGLmax FROM TAGLserial;
    Any comment would be greatly appreciated.
    Last edited by NeoPa; Jul 4 '14, 11:08 PM. Reason: Added some [CODE] tags.
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3662

    #2
    First, please use code tags when you post code.

    Second, your text box should be bound to your table, to make it easier to tie directly into that table.

    Third, to set the value of a text box, you cannot use a SELECT statement, but you can use the value from that query. To assign the value of the next ID, try this:

    Code:
    Me.txt101 = DLookup("[AGLID]", "QryMaxAGL") + 1
    Since you are only pulling one record in your query, this should work.

    There may be better ways to do what you are doing, but if you want to generate your own IDs, this is one way to do it.

    Comment

    • pbabin
      New Member
      • Jul 2014
      • 5

      #3
      I really appreciated your help. I don't want to admit the hours reading and trying. It worked like a charm.
      Thanks.
      What do you mean?
      "First, please use code tags when you post code. "
      Thanks
      I am new to this, and appreciate all recommendations .

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32661

        #4
        Originally posted by Pbabin
        Pbabin:
        What do you mean?
        "First, please use code tags when you post code."
        When posting code (of any variety) it is important to use [CODE] tags so that the code can be viewed more easily and clearly. This is a rule of the site that new members often need to be reminded of. As an illustration I've updated your first post.

        Without the tags it's very hard to see the code that you post in any sort of context. When posting your comments the [CODE] tags button is always available.

        Comment

        • pbabin
          New Member
          • Jul 2014
          • 5

          #5
          Understood and will do.!
          Thanks again for your time.

          Comment

          Working...