Adding an Unbound Text Box value to Table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mquigley
    New Member
    • Aug 2007
    • 3

    Adding an Unbound Text Box value to Table

    I have a custom function I got from the net to get the user. This displays the computer user un an unbound text box on a form. How do I add this to a table?
    I cannot pick this as a default value in the table (only custom functions here) - please point me in the right direction - I did search the web but found insufficient help - Mark
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by mquigley
    I have a custom function I got from the net to get the user. This displays the computer user un an unbound text box on a form. How do I add this to a table?
    I cannot pick this as a default value in the table (only custom functions here) - please point me in the right direction - I did search the web but found insufficient help - Mark
    1. Create a Field in the Table that is the Record Source for your Form, call it Current_User, or any name for that matter.
    2. Bind that Unbound Text Box on your Form to this Field by setting its Control Source Property to Current_User, or any name you previously designated.
    3. Set the Default Value Property of this Field to the Function as in:
      [CODE=text]=fGetUserName()[/CODE]
    4. For every New Record you add through this Form, the return value from the Function will be placed in this Text Box and saved to the underlying Table.
    5. If this Function is only to be used in this 1 Form, it can be declared as Private in the Form's Code Module.
    6. If you want it to be used by more than 1 Form, it should be declared as Public in a Standard Code Module.
    7. Feel free to ask if you need further assistance.

    Comment

    • nico5038
      Recognized Expert Specialist
      • Nov 2006
      • 3080

      #3
      An alternative is the Environ() function, you can use as default value for the field:
      Code:
      =Environ("UserName")
      Instead of "UserName" you can use also "ComputerNa me" and every other environmental variable set on the computer.

      Nic;o)

      Comment

      • mquigley
        New Member
        • Aug 2007
        • 3

        #4
        Thank you very much for replying to my post - unfortunatly neither suggestion worked (maybe it's my understanding of how this works). I would like this to work like the field in the same table that has a default value of =now() to get when the user made the entry. I am useing Access 2003 - I did not see any functions to get the =Environ() (but I did try this as a default value in my table, and Access said "Unknown Function"). any ideas here would be great! I know Microsoft has a KB article on Audit Trails, let me read that again for clues. Thank you!

        Comment

        • nico5038
          Recognized Expert Specialist
          • Nov 2006
          • 3080

          #5
          The =Environ("UserN ame") as default value will only work "behind" a form.
          Just create a form and open the properties of the field. Place the statement in the "Default value" property and add a new record.

          Nic;o)

          Comment

          • mquigley
            New Member
            • Aug 2007
            • 3

            #6
            when I edit the text box on my form the properties show the control source to be =CurrentUser() (this shows as ADMIN in the text box - my function (from the net) shows it as mfquigle). If I set the Control Source of the text box to the table ([tblProgram]![EnteredBy]) it does save any value I enter in the text box to the table, but it does not seem to save the default value (which is what I want) to the table (my function returns "#Error" when put as the default value, if I put =Environ("UserN ame") as the default value the text box returns "#Name?". I did see the Environ function in (under) the form as you said Nico - thank you -

            Comment

            • gurmet
              New Member
              • Jul 2008
              • 6

              #7
              Hi
              Thank you very much it helps me. I m able to save who creates the record by saving the network username and also date/time as when it is created.
              The above info helps me as already got the username and date just did not how to save them into the table, and above steps helps me.

              Thank you very much.
              Regards
              Gurmet

              Comment

              Working...