Results 1 to 11 of 11
  1. #1
    tsgtnissen is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Sep 2014
    Posts
    28

    Exclamation Copy from Table to Table with a filter - SOOO CLOSE TO WORKING!

    After two posts and ton of help from this community I have solved 98% of my Database issues.

    My current WORKING copy will load all the "Events" from the EventMaster table to the EventsLog table and assign them to the selected user.

    Code:
    Private Sub pbbLoadSelectedBlock_Click()
    
    'This code allows me to copy all items from EventsMaster : table to --> EventsLog : table AND assign then to the USERID of selected USERID on the form "UserDetails
    If MsgBox("Do you want to load the selected BLOCK Default Events for this user? ", vbQuestion + vbYesNo) = vbYes Then
    Me.Refresh
    Else
    MsgBox "Ok, good catch!", acSaveNo
    End If
    
    CurrentDb.Execute "INSERT INTO EventsLog(UserID,EventName,EventDiscription,EventStart,EventComplete,EventPhase,EventInstructor,EventInstructorNotes) SELECT " & Me.UserID & ",EventName,EventDiscription,EventStart,EventComplete,EventPhase,EventInstructor,EventInstructorNotes FROM EventsMaster;"
        MsgBox "New Events have been loaded!!!", vbInformation, "Success"
    
    'This will refresh the form and updates the listbox to display the new Events
    Form.Refresh
    
    
    End Sub
    The last question I have is.....

    1. Is there a way to add a Combobox that will allow me to add events from the "EventMaster" table that's EventPhase is = to the Combobox value?



    My goal is to add only certain phases not the whole list every time.

  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,521
    Add

    ...WHERE EventPhase = " & Me.ComboName

    to the end. If the field is text:

    ...WHERE EventPhase = '" & Me.ComboName & "'"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    tsgtnissen is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Sep 2014
    Posts
    28
    Code:
    CurrentDb.Execute "INSERT INTO EventsLog(UserID,EventName,EventDiscription,EventStart,EventComplete,EventPhase,EventInstructor,EventInstructorNotes) SELECT " & Me.UserID & ",EventName,EventDiscription,EventStart,EventComplete,EventPhase,EventInstructor,EventInstructorNotes WHERE EventPhase = '" & Me.cbbBlockLoadSelect & "'" FROM EventsMaster;"
         MsgBox "New Events have been loaded!!!", vbInformation, "Success"
    its not working

    The combo box values are "indoc, blk1, blk2"

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I said to add it to the end, you put it in the middle. The clauses are out of order now. Try

    Code:
    CurrentDb.Execute "INSERT INTO EventsLog(UserID,EventName,EventDiscription,EventStart,EventComplete,EventPhase,EventInstructor,EventInstructorNotes) SELECT " & Me.UserID & ",EventName,EventDiscription,EventStart,EventComplete,EventPhase,EventInstructor,EventInstructorNotes FROM EventsMaster WHERE EventPhase = '" & Me.cbbBlockLoadSelect & "'"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    By the way, most of us would use a string variable for the SQL, making it easier to debug.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    tsgtnissen is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Sep 2014
    Posts
    28
    IT WORKS!!!!!!! THANK YOU!!!!

    Code:
    Private Sub pbbLoadSelectedBlock_Click()
    'This code allows me to copy all items from EventsMaster : table to --> EventsLog : table AND assign then to the USERID of selected USERID on the form "UserDetails
    If MsgBox("Do you want to load the selected BLOCK Default Events for this user? ", vbQuestion + vbYesNo) = vbYes Then
    Me.Refresh
    Else
    MsgBox "Ok, good catch!", acSaveNo
    End If
    ' this may load 1 event//// CurrentDb.Execute ("INSERT INTO myTable (Major, Time, Ne, Escalation, Description) VALUES('" & myListBox.Column(1) & "', " & myListBox.Column(2) & ", '" & myListBox.Column(3) & "', '" & myListBox.Column(4) & "', '" & myListBox.Column(5) & "')")
    ' This will load only the selected events that match the PHASE/BLOCK that has been selected in the combobox. The WHERE command is the uniqie part.
    CurrentDb.Execute "INSERT INTO EventsLog(UserID,EventName,EventDiscription,EventStart,EventComplete,EventPhase,EventInstructor,EventInstructorNotes) SELECT " & Me.UserID & ",EventName,EventDiscription,EventStart,EventComplete,EventPhase,EventInstructor,EventInstructorNotes FROM EventsMaster WHERE EventPhase = '" & Me.cbbBlockLoadSelect & "'"
        MsgBox "New Events have been loaded!!!", vbInformation, "Success"
    'This will refresh the form and updates the listbox to display the new Events
    Form.Refresh

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    tsgtnissen is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Sep 2014
    Posts
    28
    I got it working with ONE combo box, I would like to use two but my WHERE is messed up.
    Can you help?

    Code:
    Private Sub pbbLoadSelectedBlock_Click()
    
    'This code allows me to copy all items from EventsMaster : table to --> EventsLog : table AND assign then to the USERID of selected USERID on the form "UserDetails
    If MsgBox("Do you want to load the selected BLOCK Default Events for this user? ", vbQuestion + vbYesNo) = vbYes Then
    Me.Refresh
    Else
    MsgBox "Ok, good catch!", vbOKOnly
    End If
    ' This will load only the selected events that match the PHASE/BLOCK that has been selected in the combobox. The WHERE command is the uniqie part.
    CurrentDb.Execute "INSERT INTO EventsLog(UserID,EventName,EventDiscription,EventStart,EventComplete,EventPhase,EventInstructor,EventInstructorNotes) SELECT " & Me.UserID & ",EventName,EventDiscription,EventStart,EventComplete,EventPhase,EventInstructor,EventInstructorNotes FROM EventsMaster WHERE EventPhase = '" & Me.cbbSingleBlockLoadSelect & "' EventName = '" & Me.cbbSingleEvent & "'"
        MsgBox "New Events have been loaded!!!", vbInformation, "Success"
    'This will refresh the form and updates the listbox to display the new Events
    Form.Refresh
    
    
    End Sub

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The criteria need to be separated by AND. The end result would look like:

    WHERE Field1 = 'abc' AND Field2 = 'xyz'
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    tsgtnissen is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Sep 2014
    Posts
    28
    ITS WORKING!!!!!!! THANK YOU SOOOO MUCH!

    Code:
    Private Sub pbbLoadSelectedBlock_Click()
    'This code allows me to copy all items from EventsMaster : table to --> EventsLog : table AND assign then to the USERID of selected USERID on the form "UserDetails
    If MsgBox("Do you want to load the selected BLOCK Default Events for this user? ", vbQuestion + vbYesNo) = vbYes Then
    Me.Refresh
    Else
    MsgBox "Ok, good catch!", vbOKOnly
    End If
    ' This will load only the selected events that match the PHASE/BLOCK that has been selected in the combobox. The WHERE command is the uniqie part.
    CurrentDb.Execute "INSERT INTO EventsLog(UserID,EventName,EventDiscription,EventStart,EventComplete,EventPhase,EventInstructor,EventInstructorNotes) SELECT " & Me.UserID & ",EventName,EventDiscription,EventStart,EventComplete,EventPhase,EventInstructor,EventInstructorNotes FROM EventsMaster WHERE EventPhase = '" & Me.cbbSingleBlockLoadSelect & "' AND EventName = '" & Me.cbbSingleEvent & "'"
        MsgBox "New Events have been loaded!!!", vbInformation, "Success"
    'This will refresh the form and updates the listbox to display the new Events
    Form.Refresh
    
    End Sub

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Awesome!!!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 4
    Last Post: 08-31-2020, 02:25 PM
  2. Replies: 12
    Last Post: 05-08-2019, 07:11 PM
  3. Replies: 18
    Last Post: 08-09-2018, 06:45 AM
  4. Replies: 2
    Last Post: 07-01-2016, 09:27 AM
  5. Replies: 1
    Last Post: 09-03-2014, 10:48 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