Results 1 to 5 of 5
  1. #1
    hnhpak is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Jan 2015
    Location
    Karachi Pakistan
    Posts
    28

    Post VBA Coding Append new record in one table and copy data from another table to new record

    I am preparing an attendance register for a small school

    I have two table:
    1. Students with fields (ID, [Student Name], [Class],,,, and many other fields
    2. [Std Attendance] with fields ( ID, [Attendance Date], Std ID, [Std Name], [Std Class], [Present](yes/No)

    I want to generate attendance for a date for all students by VBA Coding through a command button

    For this purpose:
    1. By using VBA code in command button (Selecting Table [Students] in command button]

    DoCmd.GoToRecord , , acFirst
    Do While Not Me.NewRecord " In Table [Students]




    2. Append new records in Table [Std Attendance] for each students for each record in Table [Students]

    3. On append Each new record in table [Std Attendance] want to auto copy following fields data from [Students] Table:
    a) [Attendance Date] from System date by command date()
    b) [Std ID] from [Students].[ID]
    c) [Std Name] from [Students].[Student Name]
    d) [Std Class] from [Students].[Class]

    Please guide how can i take my required results.

    Your help will be highly appreciated and may be helpful to others too.

    Regards

    Haseeb ul Hasan

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    Something like:

    CurrentDb.Execute "INSERT INTO [Std Attendance]([Attendance Date], [Std ID], [Std Class]) SELECT " & Date() & " AS AttendDate, [Std ID], [Class] FROM Students"


    Should not save student name into Std Attendance - that would be duplication of data.


    Advise not to used spaces or special characters/punctuation (underscore is exception) in naming convention. Better would be StdAttendance or Std_Attendance.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    hnhpak is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Jan 2015
    Location
    Karachi Pakistan
    Posts
    28
    Thanks for the reply, I tried but it won't works

    it will be highly appreciated if you could just let me advice to do this!

    [Std Attendance] table can add new records for all students in table [Students] and just fill [STD_ID] from [Students] and [Atd_Date] with Date() for every new record

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,825
    What did you try? Where did you put code? What happens - error message, wrong results, nothing?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    hnhpak is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Jan 2015
    Location
    Karachi Pakistan
    Posts
    28
    Matter has been SOLVED
    Thank you very much for your help.

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

Similar Threads

  1. Replies: 3
    Last Post: 03-09-2013, 10:39 AM
  2. Replies: 3
    Last Post: 03-05-2013, 05:14 AM
  3. Replies: 3
    Last Post: 08-09-2012, 01:49 PM
  4. copy and append a record
    By erikl1 in forum Access
    Replies: 4
    Last Post: 03-02-2012, 03:47 AM
  5. Copy record to different table
    By Patience in forum Access
    Replies: 27
    Last Post: 06-03-2010, 12:19 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