Results 1 to 5 of 5
  1. #1
    tsgtnissen is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    28

    Exclamation Copy Table to Table with Command Button - 85% solved -Just need one last thing

    Im such a Access Noob! I have everything done and working but I have one last hurdle. In my Access Program I would like a command button to copy from one table to a master table. I have this code working perfect.


    Code:
    Private Sub btnLoadIndoc_Click()' Copies One table to another .
     CurrentProject.Connection.Execute "INSERT INTO Table1(Event,StartDate,Completed,Student,Description) SELECT Event,StartDate,Completed,Student,Description FROM GradeBookIndoc;"
        MsgBox "Record Saved !!!", vbInformation, "Success"
    
    End Sub
    My question is.... on the "Form" I have the "Command Button" on, I also have a text box that has a students name.
    My desired outcome is when i click the "Command Button" it would look at the text box and read the students name, then load that name to the "Students" column on Table1.


    The theory of how this program will work is.



    1. Table1 = will hold all events my students need to accomplished
    2. GradeBookIndoc (table) = will have a template of a few events.
    3. When i pull up a student I can click a button and assign those task to them.


    ThANK YOU SO MUCH FOR THE HELp!
    Last edited by tsgtnissen; 08-31-2020 at 08:31 AM.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    If both tables are in same db, just use CurrentDb object.
    Concatenate student identifier. However, should not be student name, should be a StudentID. Presume there is a Students table. Select student with a combobox. However, if entering a new student, new record in Students must be committed before saving related records in Table1.
    Event should probably also save an ID, not an event name.
    If there is no data for a field, don't need to include it in the INSERT. I assume StartDate and Completed will be entered later. What is Description for?

    CurrentDb.Execute "INSERT INTO Table1(Event,Student,Description) SELECT Event," & Me.cbxStudent & ",Description FROM GradeBookIndoc;"

    Suggest you use a more meaningful name than Table1.
    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
    tsgtnissen is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    28
    OK, after some reworking, I now have this

    Code:
    Private Sub pbxLoadBooks_Click()
    
    If MsgBox("Do you want to load this gradebook? ", vbQuestion + vbYesNo) = vbYes Then
    Me.Refresh
    Else
    MsgBox "Ok, good catch!", acSaveNo
    End If
    
    
    
    
    CurrentDb.Execute "INSERT INTO Tasks(Title,Assigned To,Description,Block) SELECT Title," & Me.ID & ",Description,Block FROM TasksGradeBooksEvents;"
        MsgBox "Record Saved !!!", vbInformation, "Success"
    
    
    End Sub
    Click image for larger version. 

Name:	i1.PNG 
Views:	25 
Size:	32.9 KB 
ID:	42863

    The ID is the "Students" ID number from the "Students : Table"

    but in my TASKS table I was dumb and put "Assigned to"......Silly me has already added a ton of stuff that works with that (I NOW KNOW) very bad naming convention.



    Goood new....... EVERYTHING WORKS if i take out the "Assigned to" bit in the code. Its writing everything to the tasks database just fine. and my Querys are working to filter by block.


    SO... the last problem is getting it to assign the Currently selected student to the "Assigned to" field .



    ONCE AGAIN !! THANK YOU LORDS OF THE CODING WORLD! once i get this working i will go back and clean everything up, and make it much cleaner. I also need to add and delete some fields. I have been cut and pasting tons of tutorials(I KNOW ITS UGLY ATM)

    I will also post a completed working build to help other users. This will help all of the instructors at our school manage a massive amount of data once we get this going.

  4. #4
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Minor Error:

    You have
    Code:
    If MsgBox("Do you want to load this gradebook? ", vbQuestion + vbYesNo) = vbYes Then
    Me.Refresh
    Else
    MsgBox "Ok, good catch!", acSaveNo
    End If
    "acSaveNo" is not a parameter for the function "Msgbox". I think you would want "vbOKOnly".

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Assuming the ID field is numeric, is the AssignTo in table Tasks also numeric (long integer)? If the two data types match your current append (insert into statement) should work.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Use a Command Button to make a new Table???
    By ajh2014 in forum Access
    Replies: 3
    Last Post: 10-14-2014, 08:05 AM
  2. Copy From Command Button (Acc2007 form)
    By psunilve in forum Programming
    Replies: 4
    Last Post: 04-03-2013, 06:11 AM
  3. Replies: 2
    Last Post: 03-07-2012, 08:39 AM
  4. Replies: 5
    Last Post: 02-21-2012, 07:33 AM
  5. Replies: 1
    Last Post: 07-27-2010, 02:27 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