Email access query from powershell

I am trying to utilise the DoCmd.SendObject command, from powershell... I have the script launch the required database but I cannot get it to export the query information into Xl format and email it...
This ran the macro that I had produced in Access but I was then required to manually click on an Outlook warning box so it has not resolved the issues.
I just need to get this query data out of access either to save it locally and then send it via email or send it automatically...
Does anyone have any experience of this?
Your help will be most appreciated!
Regards
Richard

Hi Richard,
If you want to export the access query to excel format and send the excel report, have you tried the
DoCmd.OutputTo
Method, please also note I haven't tested
$db = New-Object -ComObject Access.Application
$db.OpenCurrentDatabase("foo.accdb")
$db.DoCmd.OutputTo(1,"The_Report","YourQueryName", "Excel Workbook (*.xlsx)", , True)
Refer to:
Powershell Interaction with Access 2007, how to Save Report as PDF?
DoCmd.OutputTo in xlsx (Excel 2007+) Format
If there is anything else regarding this issue, please feel free to post back.
Best Regards,
Anna Wang

Similar Messages

  • How to run a MS Access Query from Servlet

    Is there a way to execute an MS Access query from a servlet. I have a query that is doing an INSERT into the database. I tried to code the servlet to directly do the query itself, but it keeps locking the database and hanging. I would appreciate any help.
    Thanks,
    Justin
    [email protected]

    r u refering to the query saved inthe MSACCESS, if so then it may not be possible, bcoz it is not a pure RDBMS. otherwise the u can do it as inthe above mention thread.

  • Dynamic Access Control from PowerShell

    Hi Guys 
    Please I need your help, I am working with AD Dynamics Access Control (AD DAC)  and Windows Powershell (PS), the Idea is create a menu for AD DAC in PS, Everything is OK but I have a problem when I create  a new  ClaimType, because from AD DAC
    windows  Menu you can select an AD Attribute and there is a Column naming  "Value Type" , but in my Script I Don't know how to get this to show in OUT-GridView, I dont know what is the correct property. 
    My Code:
    Get-ADObject -SearchBase ((Get-AdRootDSE).SchemaNamingContext) -SearchScope 1 -filter *  -Property name, Ldapdisplayname | out-gridview -outputmode Single
    Sorry But I can't put my image here 
    Thanks in advance 

    Hi,
    Change the -Property parameter to a wildcard and check the output. Once you know what property you need (assuming it is actually listed), you can add it to your current list.
    As for posting screenshots, you'll need to post in the current verification thread stuck at the top of this forum here:
    https://social.technet.microsoft.com/Forums/en-US/home?forum=reportabug
    Don't retire TechNet! -
    (Don't give up yet - 13,085+ strong and growing)

  • Ms Access query from Java

    I'm trying to finish a program but there are some bugs in accessing the database, the connection opened well and i can retreive any data from the data base but when i wrote this sql statement:
    rs = stmt.executeQuery("Select number,Type, sum(charge) from invoice where date between '" + d1 +"' and '"+ d2 + "' Group By number, Type;");
    an error was appeared with:
    "data type mismatch in criteria expression"
    the d1 and d2 are variables with date datatype
    in invoice table "date" is an attribute with date/time datatype..
    anyone to help me??
    thanks all

    the real problem here that in java d1 and d2 areNo the real problem is your refusal to use Prepared Statements.
    converted from from string to date data type
    so it consists of: dayname, day , month, hour, and
    year
    and in MS Access the date attribute is consist of
    day, month and year only.. If you used Prepared Statements then this would not matter.
    so when i compare these d1and d2 in java with date in
    ms access it cause miss match data type error..
    how to make d1,d2 in the format "dd/mm/yyyy" and
    still date data type???
    USE PREPARED STATEMENTS.
    java.sql.PreparedStatement
    Look that up. Annie gave you an example in her post.

  • Writing a table to a MS Access database from Powershell

    Hey guys, me again...I'm trying to wrap up a project here and i have a powershell app writing to a SQL database just fine. The last piece is writing to a MS Access database table. For the life of me i cannot find anything out there that really points me
    in the right direction.
    I know my database name/path and i know the table/headers i need to write my data too.
    Anyone have a link to a quick dirty tutorial or can someone point me in the right direction ?
    Thanks as always
    Rich
    Rich Thompson

    I get no error message. I created a blank database with a table called dbo_so_shprimg_pvs and headers
    called so_hdr_key, so_ship_key, imgfileName, so_shprimg_crtdt. I'm doing a test write-host
    prior so i know my variables are good. 
    Rich
    Rich Thompson

  • SAP Inbound email related query (from Outlook to SAP)

    Hi,
    I am in a situation where I have to send email from MS Outlook to SAP with a PDF file as an attachment. The PDF file will be stripped into an XML file and processed further and a reply is sent to the user sending the email. The Outlook admins have set up the necessary config for the connectivity - I am able to send the PDF file from Outlook to SAP (everything has been configured using SICF, SCOT etc) for inbound processing. In SCOT - Settings->Inbound processing I have used a Class which implements interface IF_INBOUND_EXIT_BCS (as per one of the blogs by Jeff Gebo). I can see the trace file in SCOT ->Utilities->Trace->Internal trace. When I send the PDF file, I can see in the trace (I cannot debug as the SAPCONNECT user which gets called in the backgound triggers the user exit class). In the trace file I can see my class gets instantiated but the next step to read the PDF file fails.  The code come the Jeff's blog which I use is as follows:
    Set return code so that no other Inbound Exist class will be called
    e_retcode = IF_INBOUND_EXIT_BCS=>gc_terminate.
    try.
    Get the email document that was sent.
      data: document type ref to if_document_bcs.
      document = io_sreq->get_document( ).
    Get the sender's address to reply back
      lv_sender = io_sreq->get_sender( ).
      addr = lv_sender->address_string( ).
      return_addr = addr.
    Get the interactive form attachment.
      data: pdf_table type BCSS_DBPC.
      pdf_table = document->get_body_part_content( 2 ).
    Convert the pdf table into an xstring.
      data: pdf_xstring type xstring,
            pdf_line type solix.
      clear pdf_xstring.
      loop at pdf_table-cont_hex into pdf_line.
        concatenate pdf_xstring pdf_line-line into pdf_xstring in byte mode.
      endloop.
    Process the PDF form
      data: formxml type string.
      formxml = me->process_form( pdf = pdf_xstring ).
    Here the contents of the pdf_table-cont_hex is blank (I used a table to populate the values). All I get in my Outlook inbox is a empty email with an empty subject from SAP (called by the instantiated class of the Interface)
    The irony is that I setup the same procedure has been configured and setup in another totally different SAP system and everything works fine there - I did a comparision of both SAP systems and everything seems fine (config wise and user exit class wise) and  everything is identical. I have no clue as to why it works in one system and not in the other system.
    If anyone has any pointers wit will be greatly appreciated as I am on a tight deadline - I have checked OSS but with no help.
    Thanks in advance,
    Ryan

    You may be able to find more information by putting an infinite loop at the beginning of your user exit:
    x = ' '.
    while x = ' '.
    x = ' '.
    endwhile.
    and then go into debugging via SM50 and set the x variable to break out of the loop.
    This technique is useful debugging workflows and other code which you cannot get to directly by placing a break-point.
    Andrew

  • Email SQL query results from powershell

    I currently have a script that I run every half hour which runs an sql query, and takes the results, and emails them to a group of users.  The script states how many faxes are in a faxmaker queue.  Now, the powers that be would like to add additional
    information, and I wanted to know how to include the additional information in my query. So, here is the script that is working.  I've changed some information to protect the innocent.
    $DATETIME = Get-Date -Format "MM-dd-yyyy [HH:mm:ss]";
    ##### CREATE A LOG FILE AND INSERT A LOG HEADING ;
    $LOG_HEADING = "SHOW FLORIDA INBOUND FAX QUEUES RAN @: " + $DATETIME ;
    Add-Content "E:\psh\LiveScripts\logs\SHOW-FLORIDA-INBOUND-FAX-QUEUE.TXT" $LOG_HEADING ; 
    # get sql dbname  sample
    #email variables
    $EmailFrom = "[email protected]" ;
    $EmailTo = "My Email List" 
    $SqlServer = "MY-SQL-SERVER"
    $SqlCatalog = "FAXmakerArchive"
    $SqlConnection = New-Object System.Data.SqlClient.SqlConnection
    $SqlConnection.ConnectionString = "Server = $SqlServer; Database = $SqlCatalog; Integrated Security = True"
    $SqlConnection.Open()
    $SqlCmd = New-Object System.Data.SqlClient.SqlCommand
    $SqlCmd.CommandText = "SELECT count (DISTINCT fax.ID) DATONA_BEACH_FAX_COUNT FROM
    FM_FAXIN fax WITH (NOLOCK) LEFT OUTER JOIN T_FAX_REVIEW rvw WITH (NOLOCK) ON fax.ID = rvw.IDN_FAX WHERE (fax.RESULT LIKE '%SUCCESS%' OR (fax.RESULT NOT LIKE '%SUCCESS%' AND ATTACH_COUNT > 0)) AND
    ISNULL(rvw.BOOL_IS_COMPLETE, 0) = 0 AND fax.LINE IN (SELECT LINE FROM T_LOCATION_FAX_LINE lne WITH (NOLOCK) WHERE lne.CDE_ACTIVE_FLAG = 1 AND lne.IDN_LOCATION =
    3) AND fax.DATE >   '2013-09-25' "                                        
    $SqlCmd.Connection = $SqlConnection
    $NumberOfFlaInboundFaxes = $SqlCmd.ExecuteScalar()
    $SqlConnection.Close()
    if( $NumberOfFlaInboundFaxes -gt 29)
    #Email Body
    $EmailBody = @"
    There are currently $NumberOfFlaInboundFaxes Faxes in the Florida Inbound Fax Queue (  )`n
    Please Log in and help clear the Queue.  Thank you. `n
    `n`n`n
    The people who recieved this email are: $EmailTo`n`n`n
    From ApexAdmin/SystemScheduler
    $EmailSubject = "There are " + $NumberOfFlaInboundFaxes + " faxes in the Inbound Florida Fax Queue. " + $DATETIME   ;
    #End of Email Body
    #send mail via gmail through powersehll
    $SMTPServer = "smtp.gmail.com" 
    $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587) 
    $SMTPClient.EnableSsl = $true 
    $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("email user", "email password"); 
    $SMTPClient.Send($EmailFrom, $EmailTo, $EmailSubject , $EmailBody)
    Else
    Write-Host "NO ALERT  on $DATETIME `n" -foreground 'DARKGREEN' -background 'WHITE' ;
    #Write-output "There are currently: " $NumberOfFlaInboundFaxes " Faxes in the Florida Fax Queue"
    Write-Host "There are currently "  $NumberOfFlaInboundFaxes  " Files in the Florida fax queue" -foreground 'DarkBLUE' -background 'white'
    Write-Host "SMTP Alert sent to " ( "$EmailTo" ).ToUpper() " on $DATETIME `n" -foreground 'DARKBLUE' -background 'WHITE' ;
    write-Host "WROTE AN ENTRY TO THE LOGFILE.`n" -foreground 'DARKGREEN' -background 'WHITE'
    Now, I'd like to also include this query... also changed information to protect the innocent.
    SELECT u.IDN_USER,      
    u.NAM_LASDBUSER,      
    u.NAM_FIRSDBUSER,      
    r.NAM_ROLE,      
    COUNT(o.IDN_ORDER) ORDER_CNT,      
    COUNT(DISTINCT
    o.IDN_CLIENT) CLIENDBCNT,
    (SELECT IDN_ZONE FROM DBUSER_PREF p WHERE u.IDN_USER = p.IDN_USER) IDN_USER_ZONE 
    FROM DBORDER o WITH (NOLOCK)       
    INNER JOIN DBUSER u WITH (NOLOCK)        
    ON o.IDN_USER_CRTD = u.IDN_USER       
    INNER JOIN DBROLE r WITH (NOLOCK)        
    ON u.IDN_ROLE = r.IDN_ROLE      
    WHERE DATEDIFF(d, GETDATE(), o.DTE_RECORD_CRTD)>=0 AND DATEDIFF(d, GETDATE(), o.DTE_RECORD_CRTD)<=0  
    AND r.IS_INTERNAL_USER = 1
    GROUP BY u.IDN_USER, u.NAM_LASDBUSER, u.NAM_FIRSDBUSER, r.NAM_ROLE, r.IS_INTERNAL_USER 
    ORDER BY u.NAM_LASDBUSER, u.NAM_FIRSDBUSER 
    Thank you in advance for any suggestions, links, etc, you can provide.  I don't mind doing the heavy lifting, ie:  research and reading, just needed to be pointed in the right directions.
    John

    As an example this is more readable but could be improved which would make your adding a section much easier.
    $DATETIME = Get-Date -Format 'MM-dd-yyyy [HH:mm:ss]'
    $LOG_HEADING = "SHOW FLORIDA INBOUND FAX QUEUES RAN @: " + $DATETIME;
    Add-Content "E:\psh\LiveScripts\logs\SHOW-FLORIDA-INBOUND-FAX-QUEUE.TXT" $LOG_HEADING;
    $sql = @'
    SELECT count(DISTINCT fax.ID) DATONA_BEACH_FAX_COUNT
    FROM FM_FAXIN fax WITH (NOLOCK)
    LEFT OUTER JOIN T_FAX_REVIEW rvw WITH (NOLOCK) ON fax.ID = rvw.IDN_FAX
    WHERE
    fax.RESULT LIKE '%SUCCESS%' OR (
    fax.RESULT NOT LIKE '%SUCCESS%' AND ATTACH_COUNT > 0
    AND ISNULL(rvw.BOOL_IS_COMPLETE, 0) = 0
    AND fax.LINE IN (SELECT LINE FROM T_LOCATION_FAX_LINE lne WITH (NOLOCK)
    WHERE lne.CDE_ACTIVE_FLAG = 1 AND lne.IDN_LOCATION = 3) AND fax.DATE > '2013-09-25'
    $template=@'
    There are currently {0} Faxes in the Florida Inbound Fax Queue ( )
    Please Log in and help clear the Queue. Thank you.
    The people who recieved this email are: $EmailTo
    From ApexAdmin/SystemScheduler
    $subject= 'There are {0} faxes in the Inbound Florida Fax Queue. {1:MM-dd-yyyy [HH:mm:ss]}'
    $EmailFrom='[email protected]'
    $EmailTo = "My Email List"
    $SqlServer = "MY-SQL-SERVER"
    $SqlCatalog = "FAXmakerArchive"
    #run query
    $SqlConnection = New-Object System.Data.SqlClient.SqlConnection
    $SqlConnection.ConnectionString = "Server = $SqlServer; Database = $SqlCatalog; Integrated Security = True"
    $SqlConnection.Open()
    $SqlCmd = New-Object System.Data.SqlClient.SqlCommand
    $SqlCmd.CommandText = $sql
    $SqlCmd.Connection = $SqlConnection
    $NumberOfFlaInboundFaxes = $SqlCmd.ExecuteScalar()
    $SqlConnection.Close()
    # build email if needed
    if($NumberOfFlaInboundFaxes -gt 29){
    $EmailBody=$template -f $NumberOfFlaInboundFaxes
    $EmailSubject = $subject -f $NumberOfFlaInboundFaxes,[DateTime]::Now
    $SMTPServer='smtp.gmail.com"'
    $SMTPClient=New-Object Net.Mail.SmtpClient($SmtpServer, 587)
    $SMTPClient.EnableSsl = $true
    $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("email user", "email password");
    $SMTPClient.Send($EmailFrom, $EmailTo, $EmailSubject , $EmailBody)
    }else{
    Write-Host "NO ALERT on $DATETIME `n" -foreground 'DARKGREEN' -background 'WHITE' ;
    Write-Host "There are currently $NumberOfFlaInboundFaxes Files in the Florida fax queue" -foreground 'DarkBLUE' -background 'white'
    Write-Host "SMTP Alert sent to $EmailTo on $DATETIME" -foreground 'DARKBLUE' -background 'WHITE' ;
    write-Host 'WROTE AN ENTRY TO THE LOGFILE.' -foreground 'DARKGREEN' -background 'WHITE'
    \_(ツ)_/

  • Cannot send email from Powershell on Mailbox Role

    Hi,
    I am trying to send an email from Powershell on Mailbox role of Exchange server. I have installed Symantec Mail Security on Mailbox Role.
    When I try to send email using Powershell, I got the following error.
    PS C:\a> Send-MailMessage -to [email protected] -Subject "Alert Closed.. Service is restarted on Computer" -from
    [email protected] -Body "The service was found stopped on Computer it was started automatically and it is now running normally." -bodyasHTML -priority High -SmtpServer smtp.domain.com
    Send-MailMessage : Service not available, closing transmission channel. The server response was: 4.3.2 Service not active
    At line:1 char:1
    + Send-MailMessage -to [email protected] -Subject "Alert Closed.. Service is ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException
        + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage
    This command is working fine on every server except exchange server (CAS, Mailbox). Firewall is off on the servers.
    Any help will be highly appreciated.
    Regards,
    Anees

    Hi,
    Please check the similar thread .
    http://social.technet.microsoft.com/Forums/exchange/en-US/ef699832-8da9-4709-9a50-c6223b13bd95/sendmailmessage-returns-the-server-response-was-432-service-not-available?forum=exchangesvrsecuremessaginglegacy
    smtp server (smtp.domain.com) is rejecting the connection from the
     Mailbox role of Exchange server.
    So please allow the mailbox server ip address on the smtp server's (i.e. smtp.domain.com)
    receive connector to get it done 
    Regards
    S.Nithyanandham
    Thanks S.Nithyanandham

  • From my iPad I can print wirelessly in my office, but how do I print remotely via the web through my HP ePrint printer.  It is set up with an email address but i don't know how to access it from my iPad.

    I can print wirelessly in my office from my iPad, but how do I print remotely via the web to my HP ePrint printer.  The printer is set up with an email access address but I don't know how to access it from my iPad.

    Read through this for some information on how to do this:
    http://www8.hp.com/us/en/support-topics/mobile-printing/how-to-print-mobile-devi ces-ipad-iphone.html

  • I can't access iCloud, i keep getting a message to try again later. This is the first time i have tried to log into icloud. I  know my account is working, i want to access it from my macbook. I think its looking for my old icloud email, what to do?

    I can't access iCloud, i keep getting a message to try again later. This is the first time i have tried to log into icloud. I  know my account is working, i want to access it from my macbook. I think its looking for my old icloud email, what to do? I have a working apple id, i dont understand, could it be linked to an old account iD?

    Hi smccarrison,
    Thanks for visiting Apple Support Communities.
    You may find the steps in this article helpful with troubleshooting signing into iCloud:
    iCloud: Account troubleshooting
    http://support.apple.com/kb/TS3988
    All the best,
    Jeremy

  • I have 3 macs. 2 are Lion, 1 I left Snow leopard so I can access data from my old Quicken Application that doesn't work with Lion. If I move to iCloud, will I no longer be able to access my MobileMe email on the Snow Leopard mac?

    I have 3 macs. 2 are Lion, but 1 I left Snow leopard so I can access data from my old Quicken Application that doesn't work with Lion. If I move to iCloud, will I no longer be able to access my MobileMe email on the Snow Leopard mac?

    What version of word do you have? The TS3938 sounds like it's a PowerPC app- written for an old architecture that is no longer supported in Lion. If this is the case, your files are fine- you just need a newer version of word that will run in Lion in order to open them. The newest version (2011) should be readily available anywhere, and has worked fine for me ever since I switched to Lion on release day....

  • Can I directly access BEX query from web version

    Hi expert,
            Can I directly access BEX query from web version ? I know we can access bex query from webi rich client.
    Many Thanks,

    Hi,
    Yes, you can access BEx query via BICS connection (OLAP Connection).
    In SAP BusinessObjects BI 4.0 you have multiple options to connect your SAP BusinessObjects BI client to your SAP NetWeaver BW system.
    Direct BI Consumer Services (BICS)
    SAP BusinessObjects BI 4.x Relational Universe (UNX)
    SAP BusinessObjects XI 3.1 OLAP Universe (UNV) used in a SAP BusinessObjects BI 4 environment
    Web Intelligence
    Yes
    Yes
    Yes
    SAP BusinessObjects Dashboards
    Yes
    Yes
    No
    Analysis, edition for Microsoft Office
    Yes
    No
    No
    Analysis, edition for OLAP
    Yes
    No
    No
    SAP BusinessObjects Explorer
    No
    Yes
    No
    SAP BusinessObjects Design Studio
    Yes
    No
    No
    Visual Intelligence
    No
    Yes (1)
    No
    Predictive Analysis
    No
    Yes (1)
    No
    Design Studio
    Yes
    No
    No

  • How to Launch a Query from the Easy Access Menu

    Hello Experts,
    Once I have created, saved and tested my query how can I set it up so that my users can either type in a transaction at the Easy Access Menu or select my query from the Easy Access Menu and launch the query input screen that displays fields for:
    Reporting Period
    Selection Criteria - Personnel Number, Employment Status, Personnel Area etc.
    Program Selections - company code
    Output Format
    Thanks.
    Regards,
    Jeanette

    Hello Jeanette
    You may refer to following thread
    Assign transaction code to SAP Query (created via SQ01)
    Hope this helps
    Best Regards
    Reddy

  • Can I query to PowerShell scripts from Power Query ?

    Can I query to PowerShell scripts from Power Query ?
    I want to use PowerShell result for Data Visualization in Excel.
    Like importing from web, odata, hdinsight, etc,
    I want to import result of PowerShell script.
    PowerShell can do a lot of system management.
    Regards,
    Yoshihiro Kawabata 

    This is not possible today and is not something that's likely to be implemented. The combination of being able to easily share queries and being able to easily launch external scripts that can do anything supported by the current user's permissions is
    something of a security nightmare.

  • I have backed up my iPad to iCloud as prompted but my emails have disappeared from my Mailboxes. Is this suppose to happen and can I access my emails in the iCloud backup, if so how?

    I have backed up my iPad to iCloud as prompted but all my emails have disappeared from my mailboxes, is this suppose to happen? If so, how can I access my backup to see my emails?

    Thank you, I never thought about accessing webmail. They are all there.

Maybe you are looking for

  • Looking for a specific title...

    Hi, I have been scouring the usual plug-in sources for iMovie looking for a specific kind of title. Since I have not found it, I thought I would describe it here to see if anyone knows if it exists or where I can get it. I am looking for a title whic

  • Understanding boot camp and formatting backup drive for it

    somehow i never got to fully understand how boot camp works in relation to OS X and i am wondering if someone can help me out here. 1. can i install boot camp on a mac pro and have NO mac OS on the computer at all? i have an old install here on a dri

  • HT201209 How can I use app which I have received as gift.

    I have gifted a friend a application. But he has still not received any message or link regarding it. How can he receive and use tht app.

  • No iCloud on my mac

    my mac Version is 10.6.8 but i sarch for iCloud i faund nothing. any idia abaut that

  • Start of line character?

    I cannot get what appears to be a "beginning of line" character out of the first line of ASCII text that I send as a header to a binary file.  It looks like this (below) and the relevant portion of code is attached.  Will someone please point out wha