Results 1 to 5 of 5

Thread: Object Problem

  1. #1
    Join Date
    May 2005
    Posts
    1,191

    Unanswered: Object Problem

    I'm trying to put a button on my form that when clicked, will prompt the user, and if the user says "Yes", will print only the current record being viewed. So far, this is the code I've got:

    PHP Code:
    Private Sub Cmd_Btn_Print_Form_Click()

    Dim response
    response 
    msgbox("Are you sure you want to print?"vbYesNo"Print?")

    If 
    response vbNo Then GoTo EndProgram:

    On Error GoTo Err_Cmd_Btn_Print_Form_Click

        Dim PageFrom 
    As LongPageTo As Long
        PageFrom 
    frm.CurrentRecord
        PageTo 
    frm.CurrentRecord
        DoCmd
    .PrintOut acPagesPageFromPageTo

    Exit_Cmd_Btn_Print_Form_Click
    :
        Exit 
    Sub

    Err_Cmd_Btn_Print_Form_Click
    :
        
    msgbox Err.Description
        Resume Exit_Cmd_Btn_Print_Form_Click
     
    EndProgram
    :
    End Sub 
    As is, the msg box will propmt correctly and the "No" option works. But when I press "Yes", Access gives me an error msg saying "Object Required". After digging in the help for a while, I thought I would need to put
    PHP Code:
    Private Sub Cmd_Btn_Print_Form_Click(frm as Form
    at the top, but then I couldn't even get the prompt before Access gave me a large error box.

    If anyone can tell me what I'm doing wrong, and more importantly, how to fix it, I would greatly appreciate it. Thank you in advance.
    Me.Geek = True

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Hi Nick

    You want rid of that colon at the end of the If response line

    HTH
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    May 2005
    Posts
    1,191
    Thanks for the help. But that still doesn't fix my problem with the "Object required".
    Me.Geek = True

  4. #4
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    441
    I think one would usually utilize reports to print stuff.

    The "missing object" here, is possibly the frm variable which you do not set.

    set frm = me

    should do - but in stead, you could just reference through the Me keyword.

    docmd.printout acpages, me.currentrecord, me.currentrecord
    Roy-Vidar

  5. #5
    Join Date
    May 2005
    Posts
    1,191
    Thank you very much Roy, that did it. Here's my final working code for anyone with similar problems;
    PHP Code:
    Private Sub Cmd_Btn_Print_Form_Click()

    Dim response
        response 
    msgbox("Are you sure you want to print?"vbYesNo"Print?")
    If 
    response vbNo Then GoTo EndProgram

    On Error 
    GoTo Err_Cmd_Btn_Print_Form_Click
        
        DoCmd
    .PrintOut acPagesMe.CurrentRecordMe.CurrentRecord
        
    Exit_Cmd_Btn_Print_Form_Click
    :
        Exit 
    Sub

    Err_Cmd_Btn_Print_Form_Click
    :
        
    msgbox Err.Description
        Resume Exit_Cmd_Btn_Print_Form_Click
     
    EndProgram
    :
    End Sub 
    Me.Geek = True

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •