Results 1 to 4 of 4
  1. #1
    Lorlai is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    107

    Message before Appending Records

    I have a form that executes multiple queries when a button is pushed. One of these queries is to check if the employee exists in the master resource table. If they do not exist, I want to append the employee to the master table. This should only be done if the user agrees they are a new employee, however. (For example, if someone gets married, they are the same employee, just with a new name, and shouldn't be appended to the resource card). Is it possible to create a message box that displays the employee name, and if the user presses "Yes", appends the record to the master resource card, and if "No", the employee is not added?




    Thank you for your help!

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sure. Look at the options available in VBA help for MsgBox. You want the Yes/No style, and you test the result for vbYes.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Lorlai is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    107
    Thank you for your fast response Pbaldy. Is there a way to make this MsgBox work for each individual record? For instance, if I have 3 resources that are not in the master resource card:

    Joe Smith
    Smitty McSmith
    Tracy LuLu

    And I want to append Joe and Smitty, but not Tracy. Is there an easy way to display the individual record within the msgbox? Currently, when I run my message box code (shown below), all of the new resources are added when "yes" is pressed.

    Code:
    MsgBox("Do you want to add this Resource to the Master?", vbYesNo, "Add Resource?")
    
    If vbNo Then
    
    
        'Append non existing Resource to Alert Table
    
        StrSQL = "INSERT INTO Blah blah blah SQL code works and would take too long to desensitize;"
    
            DoCmd.RunSQL StrSQL
    
    Else
        'Append non exisiting Resource to Master
    
        StrSQL = "INSERT INTO Master ( Resource, [Cost] )SELECT Temp.[Name], Temp.[Rate] " & _
        "FROM Temp LEFT JOIN Master ON Temp.[Name] = Master.Resource;"
    
            DoCmd.RunSQL StrSQL
    End If
    Any help is greatly appreciated!

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Yes you could open a recordset which identifies those people not on the Master.
    Loop through the recordset, include a message to determine if person should be added or not

    Here's a rough sample from some of my data: (Student has not yet selected a Course)
    Code:
    Sub testRS()
        Dim rs As Recordset
        Dim Resp As Integer
        Set rs = CurrentDb.OpenRecordset("SELECT Student.id, Student.studentName, SelectedCourses.CourseId " _
        & " FROM SelectedCourses RIGHT JOIN Student ON SelectedCourses.StudentId = Student.id " _
        & " WHERE (((SelectedCourses.CourseId) Is Null));")
    
        Do While Not rs.EOF
            Resp = MsgBox("add " & rs!studentname & " to Master", vbYesNo)
            If Resp = vbYes Then
                MsgBox "Code to Add " & rs!studentname & " to Master goes here", vbOKOnly
               ' your code to add 
               'this record goes here 
               '
            Else
                MsgBox "Code to NOT Add " & rs!studentname & " to Master goes here, ignore this guy and get next ", vbOKOnly
               'your code to ignore this record 
               'and move on goes here
               '
            End If
            rs.MoveNext
            Loop
        End Sub
    Good luck

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

Similar Threads

  1. Produce report after appending records?
    By Astron2012 in forum Access
    Replies: 14
    Last Post: 02-20-2013, 08:40 AM
  2. Appending inventory records with current price records
    By sberti in forum Database Design
    Replies: 8
    Last Post: 11-29-2012, 10:24 PM
  3. show duplicate records when appending a table
    By bdaniel in forum Programming
    Replies: 1
    Last Post: 06-01-2011, 07:15 AM
  4. Key violation when appending records
    By slaterino in forum Programming
    Replies: 10
    Last Post: 08-26-2010, 08:25 AM
  5. Appending Records to tables with relationships
    By RubberStamp in forum Import/Export Data
    Replies: 0
    Last Post: 12-14-2008, 06:52 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