Results 1 to 3 of 3
  1. #1
    Dalagrath is offline Only a Man
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2010
    Location
    Colorado
    Posts
    45

    Updating a Table with Info


    Hello there, I am trying to update a table and adding new information when I hit a button. Now eventually this will record when a person enters and leaves the system, but I am testing this out on basic information first.

    The code I used is this:

    Code:
     
    Private Sub Command6_Click() 
    On Error GoTo Err_Command6_Click
     
    'Dim Commands for Fields/Boxes
    Dim LastName As String
    Dim FirstName As String
    Dim Number As Integer
    Dim Address As String
     
    GoSub AdditionSample
     
    AdditionSample:
    'Updating the Sample table using this
    Set rst = db.OpenRecordset("tblSample", dbOpenDynaset)
    With rst
    .AddNew
    !LastName = Form!frmSample!LastName
    !FirstName = Form!frmSample!FirstName
    !Number = Form!frmSample!PhoneNumber
    !Address = DLookup("[Address]", "[tblEmployeeInformation]", "[EmployeeID] = 1")
    .Update
    .Close
    End With
    Return
    Exit Sub
     
    Exit_Command6_Click:
    Exit Sub
     
    Err_Command6_Click:
    MsgBox Err.Description
    Resume Exit_Command6_Click
     
    End Sub
    It keeps giving me an error on the Private Sub section. What am I doing wrong?

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    why do you have GOSUB and RETURN statements in the code?? Based on your post, it sounds like you want to run the code once through, correct??

    in addition, this is from VBA help:
    You can't enter or exit Sub procedures with GoSub...Return
    which I'm pretty sure might relate to your error.

    If you do indeed want the code to only run once, why write all of that when you can simply execute one line of code that runs an sql statement to do the same thing??

    The other that's missing in the code, as I see it, is a "dim" statement for your "rst" object. That will throw an error, if nothing else does. You can't SET without DIMMING, even if you have the "require variable declaration" option turned off (I'm pretty sure about this).

  3. #3
    Dalagrath is offline Only a Man
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2010
    Location
    Colorado
    Posts
    45
    No, what I want is when I press the code, it takes the information from the form that I dedicate, and then it slams it into a table that I specify. This way, I can do something like track when someone enters or exits an application.

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

Similar Threads

  1. Replies: 3
    Last Post: 01-31-2011, 11:47 AM
  2. Replies: 1
    Last Post: 12-13-2010, 04:06 PM
  3. Replies: 8
    Last Post: 04-21-2010, 06:43 AM
  4. Replies: 1
    Last Post: 10-20-2009, 02:05 PM
  5. How do I get info from Access table to Word doc.
    By slim_jim_56 in forum Import/Export Data
    Replies: 0
    Last Post: 10-04-2007, 09:56 PM

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