Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 35
  1. #16
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496


    Quote Originally Posted by June7 View Post
    The 255 character limit is for each parameter in a parameterized query. It appears Filter property has the same limit. I wonder if the WHERE CONDITION of OpenForm/OpenReport has the same limit.

    Options I see:

    1. As ItsMe suggested, a 'temp' table to save the BookingIDs, join Bookings table to the temp table to retrieve only the records that match.

    2. Yes/No field in the Bookings table and code sets the value for each record
    2 - they are locked. How would I set yes/no?

  2. #17
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,901
    Changing value in table, not query and not on the form. You use code to write booking ID to array, could just as easily run an edit and update on a recordset of the table.
    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. #18
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    Changing value in table, not query and not on the form. You use code to write booking ID to array, could just as easily run an edit and update on a recordset of the table.
    Sounds good - how do I write to the matching row in the table?

    Create another dao? With the table as the recordset?

  4. #19
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    I'm thinking...

    Code:
    Private Sub Form_Load()
    
    
    
    
    Dim i As Long
    Dim strWhere As String, strDo As String
    Dim rs As DAO.Recordset
    Dim myArray() As Long
    Set rs = Me.RecordsetClone
        
        'closes form if record count 0
        If rs.RecordCount <= 0 Then
        MsgBox "There are no bookings listed"
        rs.Close
        Set rs = Nothing
        DoCmd.Close acForm, "frmBookingEditAdminStep"
    
    
        Exit Sub
        End If
    
    
    'gives the array a final number (minus 1 because array starts at 0)
    ReDim myArray(0 To (rs.RecordCount - 1))
    
    
    'move to first record, record it and stuff it into array and builds a string then loops through all
    rs.MoveFirst
    For i = 0 To (rs.RecordCount - 1)
    myArray(i) = rs!BookingsID
    strDo = "UPDATE tblTradingAs INNER JOIN (tblShows INNER JOIN tblBookings ON tblShows.ShowsID = tblBookings.ShowsID) ON tblTradingAs.TradingAsID = tblShows.TradingAsID SET tblBookings.BookingReflowTool = True WHERE (((tblBookings.BookingDate)=" & myArray(i) & ") AND ((tblShows.TheatreShow)=False));"
    DoCmd.RunSQL strDo
    rs.MoveNext
    Next i
    
    
    
    
    Me.RecordSource = "qryAdminStep2_KEEP" ' change recordset to the unlocked recordset
    
    
    rs.MoveFirst
    For i = 0 To (rs.RecordCount - 1)
    myArray(i) = rs!BookingsID
    strDo = "UPDATE tblTradingAs INNER JOIN (tblShows INNER JOIN tblBookings ON tblShows.ShowsID = tblBookings.ShowsID) ON tblTradingAs.TradingAsID = tblShows.TradingAsID SET tblBookings.BookingReflowTool = false WHERE (((tblBookings.BookingDate)=" & myArray(i) & ") AND ((tblShows.TheatreShow)=False));"
    DoCmd.RunSQL strDo
    rs.MoveNext
    Next i
    
    
    rs.Close
    Set rs = Nothing
    
    
    End Sub

  5. #20
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,901
    Can use DAO recordset of the table and FindFirst method.

    Or

    CurrentDb.Execute "UPDATE tablename SET fieldname=True WHERE ID=" & Me.ID

    Problem with the Yes/No field idea is if there are multiple simultaneous users, they will interfere with each other.

    The temp table (in frontend) might be best approach.
    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.

  6. #21
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    Can use DAO recordset of the table and FindFirst method.

    Or

    CurrentDb.Execute "UPDATE tablename SET fieldname=True WHERE ID=" & Me.ID

    Problem with the Yes/No field idea is if there are multiple simultaneous users, they will interfere with each other.

    The temp table (in frontend) might be best approach.
    They'd have to search the records at the exact same time - I will have it set to false right after it has executed.

    Problem I have is that the above code gives me a about to change 0 records

  7. #22
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,901
    What would prevent multiple users performing simultaneous search?

    Why are you using SQL that is a join of tables? If you have the desired booking IDs in the array, why is additional filter criteria needed?
    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.

  8. #23
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Cleaned up - execute gives me an error

    Code:
    Dim i As Long
    Dim rs As DAO.Recordset
    Dim myArray() As Long
    Set rs = Me.RecordsetClone
        
        'closes form if record count 0
        If rs.RecordCount <= 0 Then
        MsgBox "There are no bookings listed"
        rs.Close
        Set rs = Nothing
        DoCmd.Close acForm, "frmBookingEditAdminStep"
        Exit Sub
        End If
    
    
    'gives the array a final number (minus 1 because array starts at 0)
    ReDim myArray(0 To (rs.RecordCount - 1))
    
    
    'move to first record, record it and stuff it into array and builds a string then loops through all
    rs.MoveFirst
    For i = 0 To (rs.RecordCount - 1)
    myArray(i) = rs!BookingsID
    CurrentDb.Execute = "UPDATE tblBookings SET tblBookings.BookingReflowTool = True WHERE (((tblBookings.BookingsID)=" & myArray(i) & "));"
    rs.MoveNext
    Next i
    
    
    
    
    Me.RecordSource = "qryAdminStep2_KEEP" ' change recordset to the unlocked recordset
    
    
    Set rs = Me.RecordsetClone
    rs.MoveFirst
    For i = 0 To (rs.RecordCount - 1)
    myArray(i) = rs!BookingsID
    CurrentDb.Execute = "UPDATE tblBookings SET tblBookings.BookingReflowTool = False;"
    rs.MoveNext
    Next i

  9. #24
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    What would prevent multiple users performing simultaneous search?

    Why are you using SQL that is a join of tables? If you have the desired booking IDs in the array, why is additional filter criteria needed?
    I swap the form's recordsource to an unlocked one (due to many to many tables)

  10. #25
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Also I should be using DoCmd.RunSQL ("UPDATE tblBookings SET tblBookings.BookingReflowTool = True WHERE (((tblBookings.BookingsID)=" & myArray(i) & "));"), -1

    not sure if the -1 gets rid of the update table prompt

  11. #26
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    This works

    I'd appreciate a look through

    Code:
    Private Sub Form_Load()
    
    
    
    
    Dim i As Long
    Dim rs As DAO.Recordset
    Dim myArray() As Long
    Set rs = Me.RecordsetClone
        
        'closes form if record count 0
        If rs.RecordCount <= 0 Then
        MsgBox "There are no bookings listed"
        rs.Close
        Set rs = Nothing
        DoCmd.Close acForm, "frmBookingEditAdminStep"
        Exit Sub
        End If
    
    
    
    
    
    
    'gives the array a final number (minus 1 because array starts at 0)
    ReDim myArray(0 To (rs.RecordCount - 1))
    
    
    'move to first record, record it and stuff it into array and builds a string then loops through all
    rs.MoveFirst
    DoCmd.SetWarnings False
    DoCmd.RunSQL ("UPDATE tblBookings SET tblBookings.BookingReflowTool = False WHERE (((tblBookings.BookingReflowTool)=True));"), -1
    For i = 0 To (rs.RecordCount - 1)
    myArray(i) = rs!BookingsID
    DoCmd.RunSQL ("UPDATE tblBookings SET tblBookings.BookingReflowTool = True WHERE (((tblBookings.BookingsID)=" & myArray(i) & "));"), -1
    rs.MoveNext
    Next i
    
    
    
    
    Me.RecordSource = "qryAdminStep2_KEEP" ' change recordset to the unlocked recordset
    
    
    Set rs = Me.RecordsetClone
    rs.MoveFirst
    For i = 0 To (rs.RecordCount - 1)
    myArray(i) = rs!BookingsID
    DoCmd.RunSQL ("UPDATE tblBookings SET tblBookings.BookingReflowTool = False WHERE (((tblBookings.BookingReflowTool)=True));"), -1
    rs.MoveNext
    Next i
    DoCmd.SetWarnings True
    rs.Close
    Set rs = Nothing
    
    
    End Sub

  12. #27
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,901
    So as long as the form is not refreshed/requeried, the user has a form filtered to the desired records?

    I really don't see need for array and don't have to declare recordsetclone object.

    With Me.RecordsetClone
    .MoveFirst
    While Not .EOF
    CurrentDb.Execute "UPDATE tblBookings SET BookingReflowTool = True WHERE BookingsID=" & !BookingID
    .MoveNext
    Wend
    Me.RecordSource = "qryAdminStep2_KEEP" ' change recordset to the unlocked recordset
    CurrentDb.Execute "UPDATE tblBookings SET BookingReflowTool = False"
    End With

    Although with this approach, will see each record get focus on the form. Establishing a RecordsetClone object won't do that.

    With CurrentDb.Execute method, don't need SetWarnings.
    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.

  13. #28
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by June7 View Post
    So as long as the form is not refreshed/requeried, the user has a form filtered to the desired records?

    I really don't see need for array and don't have to declare recordsetclone object.

    With Me.RecordsetClone
    .MoveFirst
    While Not .EOF
    CurrentDb.Execute "UPDATE tblBookings SET BookingReflowTool = True WHERE BookingsID=" & !BookingID
    .MoveNext
    Wend
    Me.RecordSource = "qryAdminStep2_KEEP" ' change recordset to the unlocked recordset
    CurrentDb.Execute "UPDATE tblBookings SET BookingReflowTool = False"
    End With

    Although with this approach, will see each record get focus on the form. Establishing a RecordsetClone object won't do that.

    With CurrentDb.Execute method, don't need SetWarnings.
    Yeah I don't want to get any focus, I guess I could ditch the array (though it was a good learning experience)

    I noticed you used while not instead of do until > any reason?

    also >> Wend <<?

    whileend

  14. #29
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Close While using Wend

    Close Do using Loop

    Do While
    Something
    Loop

    Do Until
    Something
    Loop

    While
    Something
    Wend

    These are the rules I use:
    If you want to write code that you can exit a loop then use Do and Loop. If you do not write code in the loop to "Exit Do" then leave Do out entirely. Another reason to use Do is when you need to evaluate "Until".

  15. #30
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Thanks June, your way is far better

    I changed some of it to speed it up (It's a lot of records to go through)
    Me.RecordSource = "qryAdminStep2_KEEP" ' change recordset to the unlocked recordset
    CurrentDb.Execute "UPDATE tblBookings SET tblBookings.BookingReflowTool = False WHERE (((tblBookings.BookingReflowTool)=True));"


Page 2 of 3 FirstFirst 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Filter By Form and Apply Filter Buttons
    By JustLearning in forum Forms
    Replies: 13
    Last Post: 02-18-2015, 01:01 PM
  2. Replies: 5
    Last Post: 02-07-2013, 12:21 PM
  3. Replies: 1
    Last Post: 08-16-2012, 01:51 PM
  4. Replies: 28
    Last Post: 03-08-2012, 06:47 PM
  5. Show array of bytes as picture in form
    By HZwaan in forum Forms
    Replies: 0
    Last Post: 06-17-2010, 04:07 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