Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Jan 2003
    Location
    Pembroke Pines, Florida, USA
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Very basic VBA question (VBA (Access 2000))

    Hi all,

    This is very basic but I'm having trouble formulating the actual question in such a way that I can find a topic under Help that covers it.

    I have a form (frmAddClient) linked to an Access table (Client). I have a Save button on that form. I have code that will take the user input from that form and save a record into the linked Access table.

    The problem I'm having is that I need to update the AddUser and AddDate fields within that Access record but I do not know the syntax to do this with. In pseudocode, the idea I am trying to follow is:

    frmFormName.txtFieldName = CurrentUser ()
    frmFormName.txtFieldName = Now()

    for example, I tried the following:

    frmAddClient.AddUser = CurrentUser()
    frmAddClient.AddDate = Now()

    However, I do not KNOW the actual syntax to do the above (and my example failed). Can anyone give me the actual code to assign a value to a textbox control?

    Thanks

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    New Lounger
    Join Date
    Jan 2003
    Location
    Pembroke Pines, Florida, USA
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Very basic VBA question (VBA (Access 2000))

    Thank you much Wendell.

    I had already deduced the need for hidden text box controls to hold the values before the saving of the record, but could not figure out the syntax. Your mention of the ! operator and using Me! to refer to the current form was exactly what I needed.

    Thanks again.

  4. #3
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,493
    Thanks
    3
    Thanked 42 Times in 42 Posts

    Re: Very basic VBA question (VBA (Access 2000))

    <P ID="edit" class=small>(Edited by WendellB on 11-Feb-03 07:10. Fix momentary amnesia and change forms to triggers)</P>A very common question for Access developers. The basic trick is to use the BeforeInsert event of the form to set hidden controls linked to the appropriate fields in your table. Your psuedo code is essentially correct, but should use the ! operator rather than the . operator, and you can use Me! to refer to the current form, i.e.
    <font color=blue><font face="Georgia">
    Me!AddUser=CurrentUser()
    Me!AddDate=Now()
    </font color=blue></font face=georgia>
    I should add that as long as your tables are in an Access database, you can set default values for a field in the design of a table. The challenge comes when you want to track who and when the record was edited - then you use the BeforeUpdate event of the form, and use the code as above. With Access (Jet) databases thats about the only way - with database servers such as SQL Server, you can do it with triggers. BTW, feel free to post these kind of questions in the Access forum as well.
    Wendell

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •