Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Bradex is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Posts
    101

    Exclamation Error while switching forms

    I have 9 pages in a tab control.

    I use this code for the Next page button: Me.TabCtl0.Value = (Me.TabCtl0.Value + 1) Mod 9
    I use this code for the Previous page button: Me.TabCtl0.Value = (Me.TabCtl0.Value - 1) Mod 9

    The Next page button works flawlessly in that, if I click the Next page button from Page 9, it automatically goes to Page 1. However, if I click the Previous page button from Page 1, I get this error: Run-time error 2101: The setting you entered isn't valid for this property.

    Can somebody correct my mistake!



    Thanks!

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    What would you expect [(Me.TabCtl0.Value -1) Mod 9] to yield when Me.TabCtl0.Value = 1?

  3. #3
    Bradex is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Posts
    101
    I want it to go to Page 9 when I click 'Previous page' from Page 1.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I know what you want to accomplish. Mod 9 will not get you there. You will probably end up using an If Else End If structure.

  5. #5
    Bradex is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Posts
    101
    I am not that well versed with access. In fact, this is the first database I have created.

    Could you please write down the entire line of the code here.

    Thanks!

  6. #6
    Bradex is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Posts
    101
    I don't get it. If the same thing is possible with the next button (switching from Page 9 to Page 1) why am I not able to it with the Previous button (switching from Page 1 to Page 9). If Mod does not work, surely there must be some other way?

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Code:
    If Me.TabCtl0.Value = 1 Then
       Me.TabCtl0.Value = 9
    Else
       Me.TabCtl0.Value = Me.TabCtl0.Value -1
    End If

  8. #8
    Bradex is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Posts
    101
    Where should I paste it. Pasting it just below the previous code like this did not work:

    Code:
    Private Sub Command688_Click()
    Me.TabCtl0.Value = (Me.TabCtl0.Value - 1) Mod 9
    If Me.TabCtl0.Value = 1 Then
       Me.TabCtl0.Value = 9
    Else
       Me.TabCtl0.Value = Me.TabCtl0.Value - 1
    End If
    End Sub
    EDIT: Deleting the line
    Code:
    Me.TabCtl0.Value = (Me.TabCtl0.Value - 1) Mod 9
    did not help either

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Assuming Command688 is the "Previous" button then:
    Code:
    Private Sub Command688_Click()
        If Me.TabCtl0.Value = 1 Then
          Me.TabCtl0.Value = 9
       Else
          Me.TabCtl0.Value = Me.TabCtl0.Value - 1
       End If
    End Sub
    Poor name for the control BTW.

  10. #10
    Bradex is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Posts
    101
    This code is giving the same run time error when I press the Previous button from Page 1 and 2. In the other pages, it works fine. I am not able to understand why.

    Could you please clear this doubt as well:
    Are controls to be renamed after creating them? Is there a convention for that?
    Why should I rename a control? I can easily find the name of the control in the Property Sheet.

  11. #11
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    It is along the line of being to easily read and understand the name.
    What is 23.100.122.175? If you type that IP address into a browser, it will display the Microsoft site. Microsoft.com is a lot easier to understand than the IP address.

    Looking through code, would it be easier to know what the code links to by reading "Command33" or "btnSave" or "cmdQuit"? Without having to refer back to the form?

    What about "Combo12", "Combo14", "Combo16"? Object names like that are a real PITA when trying to trace code!


    This code is giving the same run time error when I press the Previous button from Page 1 and 2. In the other pages, it works fine. I am not able to understand why.
    In design view, open the properties sheet. click on the first tab. In the properties sheet, click on the Format tab. Look for the property "Page Index".
    Clicking on the tab control tabs, do the indexes go from 0 to 9 or 0 to 8?

    The code RuralGuy provided works in my form.

  12. #12
    Bradex is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Posts
    101
    Thanks for the explanation. Now, I understand.

    Page Index does go from 0 to 8 for the 9 pages.

  13. #13
    Bradex is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Posts
    101
    I found the answer!

    The number 9 had to be replaced with 8 as access counts my 9th page as 8.

  14. #14
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    @Steve Thanks for jumping in; I had an appointment and was gone for a while. Good explanation and Bradex has solved the issue. I think that's terrific! Good all the way around.

  15. #15
    Bradex is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Posts
    101
    Thanks a ton both of you guys! You both were awesome!

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 06-05-2013, 05:59 PM
  2. Switching backend mdb
    By GraeagleBill in forum Programming
    Replies: 18
    Last Post: 03-23-2013, 03:19 PM
  3. Replies: 5
    Last Post: 09-05-2012, 06:42 PM
  4. Replies: 1
    Last Post: 09-15-2010, 07:34 PM
  5. switching int/double
    By giladweil in forum Access
    Replies: 2
    Last Post: 07-05-2010, 01:13 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