Results 1 to 4 of 4
  1. #1
    BugsyFrank is offline Novice
    Windows 8 Access 2013
    Join Date
    Aug 2015
    Posts
    3

    Need to create a CaptionCall for buttons.

    I have read Gord Thompson's reply to the same question and attempted to apply the code that was given in the previous forum but I cannot get the code to work.



    I have created a module called CaptionCallModule and here is what it looks like:

    Option Compare Database


    Private Sub frmMainMenu_Open(Cancel As Integer)
    DVD_CD_Inventory_List.Caption = DLookup("Caption", "MainMenu", "ID=1")
    frmBorrower.Caption = DLookup("Caption", "MainMenu", "ID=2")
    frmDVD_CD_Check_Out_In.Caption = DLookup("Caption", "MainMenu", "ID=3")
    frmMedia.Caption = DLookup("Caption", "MainMenu", "ID=4")
    frmQuickSearchMedia.Caption = DLookup("Caption", "MainMenu", "ID=5")
    rptBorrower.Caption = DLookup("Caption", "MainMenu", "ID=6")
    rptMediaList.Caption = DLookup("Caption", "MainMenu", "ID=7")
    rptPastDue.Caption = DLookup("Caption", "MainMenu", "ID=8")

    End Sub


    Private Sub DVD_CD_Inventory_List_Click()
    DVD_CD_Inventory_List.Caption = DLookup("Caption", "MainMenu", "ID=1")
    Dim varBorrower As Variant
    varBorrower = DLookup("[FRName]", "MainMenu", "[ID]=1")
    DoCmd.OpenForm varBorrower, acViewForm

    DVD_CD_Inventory_List_Click_Exit:
    Exit Sub

    End Sub




    Private Sub frmBorrower_Click()
    frmBorrower.Caption = DLookup("Caption", "MainMenu", "ID=2")
    Dim varPerson As Variant
    varPerson = DLookup("[FRName]", "MainMenu", "[ID]=2")
    DoCmd.OpenForm varPerson, acViewForm

    frmBorrower_Click_Exit:
    Exit Sub

    End Sub


    Private Sub frmDVD_CD_Check_Out_In_Click()
    frmDVD_CD_Check_Out_In.Caption = DLookup("Caption", "MainMenu", "ID=3")
    Dim varDVDCD As Variant
    varMedia = DLookup("[FRName]", "MainMenu", "[ID]=3")
    DoCmd.OpenForm varDVDCD, acViewForm

    frmDVD_CD_Check_Out_In_Click_Exit:
    Exit Sub

    End Sub


    Private Sub frmMedia_Click()
    frmMedia.Caption = DLookup("Caption", "MainMenu", "ID=4")
    Dim varMedia As Variant
    varMedia = DLookup("[FRName]", "MainMenu", "[ID]=4")
    DoCmd.OpenForm varMedia, acViewForm

    frmMedia_Exit:
    Exit Sub

    End Sub


    Private Sub frmQuickSearchMedia_Click()
    frmQuickSearchMedia.Caption = DLookup("Caption", "MainMenu", "ID=5")
    Dim varSearch As Variant
    varSearch = DLookup("[FRName]", "MainMenu", "[ID]=5")
    DoCmd.OpenForm varSearch, acViewForm

    frmQuickSearchMedia_Exit:
    Exit Sub

    End Sub


    Private Sub rptBorrower_Click()
    rptBorrower.Caption = DLookup("Caption", "MainMenu", "ID=6")
    Dim varSubject As Variant
    varSubject = DLookup("[FRName]", "MainMenu", "[ID]=6")
    DoCmd.OpenReport varSubject, acViewReport

    rptBorrower_Exit:
    Exit Sub

    End Sub




    Private Sub rptMediaList_Click()
    rptMediaList.Caption = DLookup("Caption", "MainMenu", "ID=7")
    Dim varList As Variant
    varList = DLookup("[FRName]", "MainMenu", "[ID]=7")
    DoCmd.OpenReport varList, acViewReport

    rptMediaList_Exit:
    Exit Sub

    End Sub




    Private Sub rptPastDue_Click()
    rptPastDue.Caption = DLookup("Caption", "MainMenu", "ID=8")
    Dim varDue As Variant
    varDue = DLookup("[FRName]", "MainMenu", "[ID]=8")
    DoCmd.OpenReport varDue, acViewReport

    rptPastDue_Exit:
    Exit Sub

    End Sub

    This is throwing a runtime error 424 and the debugger highlights the rptMediaListCaption line.

    I am using Access 2013. I really need to get this to work. It is for college but you can see I am really trying.

    If anyone can help I would greatly appreciate it.

    Thanks,
    BugsyFrank

  2. #2
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,399
    what is error 424? And which rptMediaListCaption line? - there are at least two

  3. #3
    BugsyFrank is offline Novice
    Windows 8 Access 2013
    Join Date
    Aug 2015
    Posts
    3

    Smile

    Quote Originally Posted by Ajax View Post
    what is error 424? And which rptMediaListCaption line? - there are at least two
    Hello Ajax.
    Thanks for replying.

    The rptMediaList.Caption.... after the Private Sub rptMediaList_Click() code is what the debugger is highlighting as wrong.

    I gave up working on this project because I was tired of trying to figure it out and failing. It would still be nice to know how to get this to work though.

    Here was the original assignment that we were given. I already turned it in. If I got 5 points out of the 15 possible I will be happy.

    1) Create a table MainMenu with at least 3 fields: ID, caption, and form or report to run

    2) Your code (for the button) will dynamically read the caption from the table and assign it to the button

    HINT: Variables (table name) in other areas of the code should not be "hard-coded". If for example a Table name changes in the database it should be reflected in the menu. I do not need to go into the code and look for all entries for the hard-coded name of the table. Dynamic caption means should the name of any table change – the caption on the button for that table must change as well. Test it out …

    3) Your code (for the button) will dynamically read the form/report name and will run when you press the button.


    HINT: Like the hint for #2 above do the same for the reports. No names should be hard-coded. This prevents errors in the long run which often break a program, and maintenance does not become a nightmare!! This approach is a widely utilized practice amongst professional developers in support of friendly user experience enhancements! Our users want to be able to press buttons that are logical, practical, and smart.

    I would try to attach my DB for you to look at but it is too big a file.

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    Since you're curious, as a student should be, Error 424 is 'Object Required.' The Access Gnomes have no way to know what 'rptMediaList' is, given your code...you have to tell them! One way would be like this

    Code:
    Reports("rptMediaList").Caption = DLookup("Caption", "MainMenu", "ID=7")


    Also note that rptMediaList has to be Open, in order to do this, or the Gnomes still won't be able to find it.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Create a calculated field from sum of radio buttons
    By antimoneylaundering in forum Access
    Replies: 6
    Last Post: 08-07-2015, 04:29 PM
  2. Replies: 21
    Last Post: 06-03-2015, 07:14 PM
  3. Replies: 25
    Last Post: 10-30-2013, 12:40 AM
  4. Replies: 4
    Last Post: 08-19-2013, 10:29 AM
  5. Replies: 1
    Last Post: 08-15-2013, 08:12 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