Page 1 of 3 123 LastLast
Results 1 to 15 of 37
  1. #1
    imintrouble is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    Missouri, where frownin's a sport
    Posts
    127

    Different Table

    Hello! I've created a form that so far does a couple of things.



    First: The form will record the users name, E-mail address, and the User type (Human Resources, Security, etc...)

    Second: It also takes the current date and the current time and inputs them into two seperate text boxes.

    My question is this, How do I take the information garnered from the Date and Time boxes and, when I push a button, the two are saved to a different Table for recording those specific things.

    All previous information, name/e-mail are to be saved to a user table seperatly. Thanks!

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Hi imintrouble,

    Try this Code behind your Command Button:
    I have textboxes txtStartDate & txtStartTime on my Form.
    I have Table fields StartDate & StartTIme.
    I'm inserting StartDate & StartTime variables [from the Form TextBoxes] into the Table.

    Code:
     
    Dim StartDate, StartTime As Date
     
    Me.txtStartDate.SetFocus
    StartDate = Me.txtReportDate
     
    Me.txtStartTime.SetFocus
    StartTime = Me.txtReportTime
     
    StrSQL = "INSERT INTO TableName (StartDate, StartTime) "
    StrSQL = StrSQL & "VALUES (" & "#" & StartDate & "#" & ", " & "#" & StartTime & "#" & "); "
     
    'MsgBox StrSQL
     
    DoCmd.RunSQL StrSQL
    I hope this helps.

  3. #3
    imintrouble is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    Missouri, where frownin's a sport
    Posts
    127
    Thanks. I tried the code by going into the code for the actual form and, after changing the correct items to fit mine (ex: txtStartDate -> txtDate), I ran the code and saw that it wasn't actually working. I'm not sure what I'm supposed to do or if I even entered the code correctly.

    What I did was went into the module for the form and simply entered the code with the modified variables.

  4. #4
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Hi again!

    My idea was that you put your code behind a command button - not in a Module for the form.

    You said in your initial post that you have a command button on your Form - right?

    The code has to be in the Clicked Event of the command button in order for it to work.

    So . . .
    Select the Command button.
    Open the Property Sheet for the button.
    Click on the Events Tab.
    Click on the [...] to the right of the On Click row.
    Paste the Code into the On_Click event that Access opens up in your Visual Basic Editor.

    Now - when you run your Form and Click on the command button, you should see the code execute and the data added to your Table[s].

    Let me know if you have trouble with this.

  5. #5
    imintrouble is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    Missouri, where frownin's a sport
    Posts
    127
    Thanks Robeen. I think I understand what you're meaning now by this. I do have one other question though. When I like the [...] it takes me to a message box where I have to choose one of three builders. I'm going to try the code builder, the other two are expression and macro builder, just because I think this sounds the most right. If i'm wrong please let me know.

    *EDIT* So I tried thecode, and when I tried to run it I got a Compile error: Method or data member not found

    the Private Sub Login_Click() is highlighted as well.

  6. #6
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    For putting the Code in - the Code Builder is the correct choice.

    Is your command button named 'Login'?

    Check the Name property of your Command Button:
    Right - Click the button in design view.
    Open the Property Sheet.
    Click the All Tab.
    The very first property should be Name.

    Now - where you have the Code for the button - make sure that you have the the correct 'Sub' that you are putting your code into:
    Private Sub Login_Click() - would be correct if the name of your Command button is 'Login'.

    Would you mind posting your code for the button in here?
    EVerything from the Private Sub Login_Click() - to the End Sub.

  7. #7
    imintrouble is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    Missouri, where frownin's a sport
    Posts
    127
    Private Sub Login_Click()
    Dim Date_Worked, Strt_Time As Date

    Me.txtDate.SetFocus
    Date_Worked = Me.txtReportDate

    Me.txtTime.SetFocus
    Strt_Time = Me.txtReportTime

    StrSQL = "INSERT INTO Users (Date_Worked, Strt_Time) "
    StrSQL = StrSQL & "VALUES (" & "#" & Date_Worked & "#" & ", " & "#" & Strt_Time & "#" & "); "

    'MsgBox StrSQL

    DoCmd.RunSQL StrSQL
    End Sub

  8. #8
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Just to confirm - IS your command button on the Form actually named 'Login'?

  9. #9
    imintrouble is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    Missouri, where frownin's a sport
    Posts
    127
    yes, under the Name field, it is named Login

  10. #10
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Any chance that you can post your database here?

  11. #11
    imintrouble is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    Missouri, where frownin's a sport
    Posts
    127
    not exactly sure how

  12. #12
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Make a copy of your database - and zip the copy.

    Then - in here - when you reply - click 'Go Advanced'.

    Under the window where you type your reply, you will see a manage attachments button - that is where you will upload your zipped file into this thread.

  13. #13
    imintrouble is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    Missouri, where frownin's a sport
    Posts
    127
    ok, but please understand that alot of the information included in the database is sensitive, so ill be sending over a copied version with those certain sections taken out. Thanks again.

  14. #14
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    That's a good idea.

    In your copy - only leave the bare minimum in there.
    Just the parts that you need help with.

    Whatever you need to maintain your privacy and security.

  15. #15
    imintrouble is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    Missouri, where frownin's a sport
    Posts
    127
    Here it is.

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 08-01-2011, 11:35 PM
  2. Replies: 2
    Last Post: 10-27-2009, 07:09 AM

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