Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2012
    Posts
    68

    Unanswered: Sendobject if field = yes question

    tblContacts

    Relevant fields are:
    "Share Contact Info" (yes/No check box)
    "E-mail Address"

    frmContact List

    Button on form called "Share Contacts"

    qryShared Contacts populates with 'yes' in the critera of "Shared Contacts

    Judging by what i have read what i need is a VBA kinda like this:

    Code:
    Private Sub Command349_Click()
    
    iif([Share Contact Info] = yes, DoCmd.SendObject(acSendReport,"rptShared Contacts",acFormatPDF,,,,,,,)
    Getting an error though. Little help?

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    If you're getting error messages and you want help with them, it'ds probably a good idea to include them in your post! But a couple of things:

    First:

    iif([Share Contact Info] = yes, DoCmd.SendObject(acSendReport,"rptShared Contacts",acFormatPDF,,,,,,,)

    You have 3 parentheses; parens always have to appear in pairs, called opening and closing parentheses.

    Secondly, your syntax for the SendObject code is incorrect. When entering Arguments like this, you only use commas between Arguments, as a place holder between Arguments, if an Optional Argument is omitted, or as a place holder before Arguments, if an Optional Argument to the left of an Argument is omitted. You do not include trailing commas, as you've done

    iif([Share Contact Info] = yes, DoCmd.SendObject(acSendReport,"rptShared Contacts",acFormatPDF,,,,,,,)

    Finally, your syntax is incorrect for the SendObject portion of your code. This is not Function, where you enclose Arguments with parens, so

    DoCmd.SendObject(acSendReport,"rptShared Contacts",acFormatPDF,,,,,,,)

    should simply be

    DoCmd.SendObject acSendReport, "rptShared Contacts", acFormatPDF

    so your entire code, as given, should be

    Code:
    iif([Share Contact Info] = yes, DoCmd.SendObject acSendReport,"rptShared Contacts",acFormatPDF)
    Now, the question is, why are you using the IIF() function? You have no Argument instructing Access what to do if [Share Contact Info] is not equal to Yes. Why not simply use the If...Then construct?

    If you plan having something for Access to do if [Share Contact Info] is not equal to Yes, it would go here

    Code:
    iif([Share Contact Info] = yes, DoCmd.SendObject acSendReport,"rptShared Contacts",acFormatPDF, DoItHere)
    Linq ;0)>
    Last edited by Missinglinq; 03-31-12 at 12:29.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Mar 2012
    Posts
    68
    Linq,
    Thanks a bunch for the help. Answers like these help me understand whatnim doing wrong. Kudos!
    As for the issue I think I was going about this a harder way than it needed to be. I created a button, afterclick macro builder, used sendobject. Was alot simpler, but thanks again for the analysis.

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Glad you got it working, and the simplest method is usually the best, but if you're planning on doing any serious programming you're going to have to use VBA code. Macros are fine, for something simple like this, but they're way less flexible than code!

    Good luck with your project!

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

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