Results 1 to 3 of 3
  1. #1
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544

    Question Update Table using VB

    I'm looking for a method for which I can update a table using VB when my form loads. The reason for this is I want the table to be updated the second the user loads the form, so I don't want to use the method of assigning data to a text box and then associating that text box with the necessary table field. The code I have in there now assigns the user name (data I need to be appended to this other table) to an unbound text box.
    Code:
    Private Sub Form_Load()
    Dim Div As String, OrgID As String, Nam As String, RV As String, LogonName As String, UserGroup As String
    DoCmd.Maximize
     
    Ans = FindLogonUserParms(OrgID, RV, LogonName, UserGroup)
    gblUserIDSelected = RV
    gblDivSelected = Div
    gblUsersLogonName = LogonName
    gblOrgSelected = OrgID
    gblUserGroup = UserGroup
     
    Me!RV = gblUserIDSelected
    'Me!Div = gblDivSelected
    'Me!DivisionName = gblDivSelected & " Division"
    Me!UsersLogonName = gblUsersLogonName
    Me!OrgID = gblOrgSelected
    Me!UserGroup = gblUserGroup
     
    End Sub
    I want to take "RV" and append it to a table called tblUserTrack and the FieldName is UserID.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    If you assigned the value to a bound textbox and immediately saved the record, there would be little if any time difference. That said, you can either open a recordset on the table and use the AddNew method or create and execute an SQL string:

    strSQL = "INSERT INTO..."
    CurrentDb.Execute strSQL
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    sounds like you are implementing tracking/logging of user activity; there is more than one way to skin the cat - - but your sample code isn't one of them....the advice to use an Insert or Update query is better.

    But it really depends on what you are attempting to track. To track that someone simply looked at a form? or a specific record? etc etc. And it depends on where the logging is recorded - a separate stand alone table or in the record being viewed.

    If it is the record being viewed, which means you will over write a new value everytime someone is in it...it can be as simple as a me.IDField = type statement in the OnCurrent event...

    All I'm trying to say is the right advice on this technically depends on what the objective is....

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

Similar Threads

  1. Replies: 1
    Last Post: 05-17-2010, 12:03 PM
  2. Why doesn't the table & Query update?
    By U810190 in forum Forms
    Replies: 1
    Last Post: 03-29-2010, 04:07 AM
  3. Replies: 3
    Last Post: 01-21-2010, 08:10 PM
  4. Update table
    By metro17 in forum Forms
    Replies: 0
    Last Post: 09-23-2009, 04:42 PM
  5. Replies: 4
    Last Post: 09-03-2009, 02:01 PM

Tags for this Thread

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