Results 1 to 10 of 10
  1. #1
    mcomp72 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    92

    Tabular form not allowing a button to work beyond the first record

    Hey everyone. I've got a form that shows the records in a tabular format. At the end of each record I have a button that opens another form with more details on that specific record.

    I took my form, which was working perfectly, and made a copy of it so I could make another form that looked similar. Here's what that form (the new one) looks like in design view.



    Click image for larger version. 

Name:	Form in design view.jpg 
Views:	13 
Size:	160.0 KB 
ID:	31411

    When I go into form view, I see all the records. However, the OPEN button doesn't work except on the very first record. I can't figure out why. On the first version of this form I made, this problem doesn't happen. Obviously I've messed something up when I created the copy, but can't figure out what it is. Any thoughts on what might be wrong?

    Here's what the Form looks like in form view. (I went into MS Paint and put a white box over the names of the people, since they are real people.)

    Click image for larger version. 

Name:	Form in form view.jpg 
Views:	13 
Size:	144.8 KB 
ID:	31412

  2. #2
    mcomp72 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    92
    Here's the code for the button click.

    Code:
    Private Sub OpenButton_Click()
    
    Dim recordID As Integer
    
    recordID = Me.TimecardID
    
    DoCmd.OpenForm "Timecards", , , "TimecardID = " & recordID
    
    End Sub
    One thing that is different between the first form (the one that worked fine) and this one: the Control Source for the first one was based on a table. The Control Source for this one is a Query. I did it that way because I needed to show the employee's name in this new one, and their name came from a different table. So I created a Query to allow me to show all the data I wanted to see. I don't want my user to be able to make any changes to the data, so I have locked the text boxes on this form... at least I think I have. Maybe by doing that I messed something up with my button?

    I don't know if this would have anything to do with it, but here is the SQL of the Query.

    Code:
    SELECT T_Timecards.WeekEnding, T_Timecards.TOTALAMT, T_Timecards.BoxRentalTotalAmt, T_Timecards.MileageTotalAmt, T_Timecards.NumberDaysWorked, T_Timecards.PrintedAlready, T_Timecards.JobID_notFK, [Q_Employees on Jobs].CombinedName, T_Timecards.TimecardID
    FROM [Q_Employees on Jobs] INNER JOIN T_Timecards ON [Q_Employees on Jobs].[EmployeesOnJobsID] = T_Timecards.[EmployeesOnJobsID];

  3. #3
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Methinks it's because you're not closing or requerying the form that you're opening in between calls. Not sure because I don't know what this means
    on the very first record, it works fine
    If you don't understand my meaning, you'll have to provide details about what the user is doing after the first attempt, and what happens in detail.
    Last edited by Micron; 11-24-2017 at 11:21 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    mcomp72 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    92
    I made a video to show you what I mean. You can find it here:
    https://youtu.be/6A-dCQ1ZSOg

    You will see that there are 12 records being shown. I start at the bottom, and click on the button on each record, moving up one record after each attempt. The button does not do what it is supposed to do (in fact, it does nothing at all) until I get to the very first record -- then it works fine. I don't understand why this is. I have a similar form that has the exact same button, and it works on all the records being shown.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Do a test with the form based on table instead of query. Do you get the same behavior as the other form?
    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. #6
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    I see that the first record is the active record.
    Pick a different record (stick with the same field so as not to introduce another variable) and repeat. If you find the code runs when clicking the button on that record, then that would be very odd. What I see at some points is screen flicker, like something attempts to open (perhaps your form opens and closes right away, or the Open event is cancelling because of code). Suggest you put msgbox recordId right before

    DoCmd.OpenForm "Timecards", , , "TimecardID = " & recordID

    and/or put a break on the top of the procedure and click one of the lower buttons as before. This will
    - tell you if the event is firing regardless of which button you click
    - enable you to check the value of id (if it's null or invalid, the following might be relevant)
    - let you follow the code execution to see if it is branching to the form you want to open but is cancelling the Open event (or simply closing the form)

    If none of that helps, I'm thinking the form is corrupted, but I hate to jump to that conclusion. Try the above to see what happens.

  7. #7
    mcomp72 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    92
    I just changed the Control Source to T_Timecards, which is the table that holds the time card data. Same problem as before. The OPEN button only works on the first record. I guess that means it's not the SQL statement for the query?

  8. #8
    mcomp72 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    92
    Here's all the code associated with that form, in case it's helpful.

    Code:
    Option Compare Database
    Option Explicit
    
    Private Sub Form_Current()
    
    Me.OrderBy = "WeekEnding"
    
    Me.OrderByOn = True
    
    End Sub
    
    Private Sub OpenButton_Click()
    
    Dim recordID As Integer
    
    recordID = Me.TimecardID
    
    DoCmd.OpenForm "Timecards", , , "TimecardID = " & recordID
    
    End Sub
    
    Private Sub Form_Load()
    
    Dim strFilter As String
    Dim CurrentJobID As Long
    
    CurrentJobID = Forms![Jobs]![JobID]
    
    'this section filters the results that will show in this form to the ones that are assigned to this particular job.
    With Forms![Timecards_NotPrintedYet]
    
        .Filter = "([JobID_notFK] = " & CurrentJobID & ")" & " AND ([PrintedAlready] = " & False & ")"
        .FilterOn = True
    
        .OrderBy = "WeekEnding"
        .OrderByOn = True
    
    End With
    
    End Sub

  9. #9
    mcomp72 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    92
    I've noticed something else that may be helpful. In the first record, I can place my cursor inside the text boxes. I can't change what is in there, but it does allow me to place my cursor inside them. I cannot do that on any of the other records. So it's as if the other records aren't really there. Every seen anything like that before?

  10. #10
    mcomp72 is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    92
    I just solved it. The OnCurrent Sub of the Form was causing a problem. I removed it and now it works fine. Weird. I have an OnCurrent sub on the other form that is similar to this one, and that one works fine. Oh well... at least it's working now.

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

Similar Threads

  1. Replies: 8
    Last Post: 10-25-2017, 01:59 PM
  2. Replies: 3
    Last Post: 02-08-2015, 01:30 PM
  3. Add new Record button doesnt work
    By zmbaker in forum Forms
    Replies: 1
    Last Post: 07-25-2014, 03:28 PM
  4. Replies: 1
    Last Post: 11-24-2010, 09:51 AM
  5. make Add Record button work
    By janjan_376 in forum Forms
    Replies: 3
    Last Post: 06-05-2009, 04:22 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