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

    Append New Resource if VBYes help

    I have some code that will append a new resource if the user selects the yes button on a dialog box. For some reason, nothing happens when the user selects yes. Am i missing a step in my code? For the life of me I cannot see a problem!



    Code:
    Dim userResponse As Integer
    Dim rs As Recordset
    Set rs = CurrentDb.OpenRecordset("SELECT Temp.[Employee/Supplier], Temp.[Bill Rate], MasterCard.Resource " & _
                                     "FROM Temp LEFT JOIN MasterCard ON Temp.[Employee/Supplier] = MasterCard.Resource " & _
                                     "WHERE (((MasterCard.Resource) Is Null));")
        Do While Not rs.EOF
            userResponse = MsgBox("Do you want to add " & rs![Employee/Supplier] & " to the Master Card?", vbYesNo)
                If userResponse = vbYes Then
                                  
                    'Append non exisiting Resource to Rate Card
    
                    StrSQL = "INSERT INTO MasterCard ( Resource, [Rate] )SELECT Temp.[Employee/Supplier], Temp.[Bill Rate] " & _
                    "FROM Temp LEFT JOIN MasterCard ON Temp.[Employee/Supplier] = MasterCard.Resource WHERE Temp.[Employee/Supplier] =' " & rs![Employee/Supplier] & "';"
    
                         DoCmd.RunSQL StrSQL
                 
                End If
            rs.MoveNext
        Loop
    Is there anything I can do to make this code work? Thank you for your help!

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Try:
    Code:
    Dim rs As Recordset
    Set rs = CurrentDb.OpenRecordset("SELECT Temp.[Employee/Supplier], Temp.[Bill Rate], MasterCard.Resource " & _
                                     "FROM Temp LEFT JOIN MasterCard ON Temp.[Employee/Supplier] = MasterCard.Resource " & _
                                     "WHERE (((MasterCard.Resource) Is Null));")
        Do While Not rs.EOF
             
                If MsgBox("Do you want to add " & rs![Employee/Supplier] & " to the Master Card?", vbYesNo) = vbYes Then
                                  
                    'Append non exisiting Resource to Rate Card
    
                    StrSQL = "INSERT INTO MasterCard ( Resource, [Rate] )SELECT Temp.[Employee/Supplier], Temp.[Bill Rate] " & _
                    "FROM Temp LEFT JOIN MasterCard ON Temp.[Employee/Supplier] = MasterCard.Resource WHERE Temp.[Employee/Supplier] =' " & rs![Employee/Supplier] & "';"
    
                         DoCmd.RunSQL StrSQL
                 
                End If
            rs.MoveNext
        Loop
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Lorlai is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    107
    Thank you, this made everything work!

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

Similar Threads

  1. If vbYes and vbNo Not Working
    By burrina in forum Forms
    Replies: 8
    Last Post: 01-03-2013, 11:00 AM
  2. Replies: 5
    Last Post: 10-22-2012, 07:52 AM
  3. Replies: 13
    Last Post: 05-11-2012, 11:27 AM
  4. Excess Resource (MSDB)
    By mei909 in forum Programming
    Replies: 1
    Last Post: 09-04-2011, 12:15 AM
  5. Resource/Timesheet Database Design
    By lynchoftawa in forum Database Design
    Replies: 0
    Last Post: 06-06-2009, 10:57 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