directly print when using code in VB.NET - vb.net

I use the following code
Dim PrintR_ As Printing.PrinterSettings = ReportViewer1.PrinterSettings
PrintR_.PrinterName = "Microsoft XPS Document Writer"
ReportViewer1.PrintDialog(PrintR_)
However, when executed, the following form appears
All I want is not to see this screen and to print directly based on the printer's specific name
Thanks for everyone who helps.

Related

Access VBA: Get Recordset from an embedded form

I am trying to access a value within a continuous form, and then pass that to a new form that is opened. I got this working properly, but it only works if the original form is open directly. It fails if I try and run this when the form is embedded within another form.
The error I get is;
Run-Time error '2450': MS access cannot find the referenced
'ViewerForm'
The code I am using is; (courtesy of here: Get Control or Recrdset Value on Continous Form)
Dim r As DAO.Recordset
Set r = Forms![ViewerForm].RecordsetClone 'Clone the recordset
r.Bookmark = Forms![ViewerForm].Bookmark 'Navigate to the active record
Myvalue = r!TagMain.Value
Why does the code work when I am opening the form by itself, yet fails when it is embedded within another form? Do I have to tell it the path through, to find the embedded form, such as
Forms![FormTheViewerIsEmbeddedWithin]![ViewerForm].RecordsetClone
Instead of
Forms![ViewerForm].RecordsetClone
ViewerForm is the subform control on the main form. The control has no RecordsetClone.
You need the (sub)form that's inside it:
Forms![FormTheViewerIsEmbeddedWithin]![ViewerForm].Form.RecordsetClone
If you get the error MS access cannot find the referenced 'ViewerForm', your subform control has a different name than the subform. Check its properties in the main form.

opening the Windows Print Pictures dialog using VB.Net

I want to call the Windows Print Pictures dialog using VB.net. the one Windows comes up with when you go to print a picture, the one that lets you print full page, 8X10, 4X6, 5X7, contact sheet, etc.
I've tried using printdocument and printdialog but those only give you the standard print dialog window for documents.
I've searched Google and all the results were completely unrelated to the Print Pictures dialog and therefore completely useless.
I've seen the same question for C+ here
Print image using windows print image dialog
using CLSID_PrintPhotosDropTarget COM object.
but this doesn't really help me since I'm using VB.net (Visual Studio 2008 to be precise) but I'm including it here as it has a screenshot of the dialog I am trying to call.
any help would be appreciated.
Okay, just this once, I will translate for you but you need to find an on line converter that you like. Many examples are available in C#. Also please take the tour to learn how to ask a proper question.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'The C# code
'String fileName = #"C:\Development\myImage.tif";//pass in Or whatever you need
'var p = New Process();
'p.StartInfo.FileName = fileName;
'p.StartInfo.Verb = "Print";
'p.Start();
Dim fileName = "C:\Users\xxxx\Desktop\Graphics\Baby owl.jpg"
Dim p = New Process
p.StartInfo.FileName = fileName
p.StartInfo.Verb = "Print"
p.Start()
End Sub

Check if Adobe Reader is installed before using it

I want to be able to have my app check if Adobe Reader is installed.
If it is, I want my program to use it to display the PDF, if not I want to use my free (limited) reader control to display the PDF.
Any suggestions
Edit:
my question seems to be little to broad
So basicly i'm trying to do the following
Try
Dim AcroDisplay As New AxAcroPDFLib.AxAcroPDF
AcroDisplay.Left = 50
AcroDisplay.Top = 50
AcroDisplay.Width = 200
AcroDisplay.Height = 500
me.Controls.Add(AcroDisplay)
MsgBox("Acro Added")
Catch ex As Exception
MsgBox("Acro Not installed")
''Load Alternate PDF viewer (Spire.pdf Free)
End Try
However when Acrobat Isn't installed instead of going to the catch statement it just shows an error "Could not load assembly" and then exits the sub
What i want is that if acrobat control isn't installed, that it wont display and error and instead just load the alternate pdf viewer
is there a way to check for AxAcroPDFLib.AxAcroPDF before attempting to load?
Hopefully this makes things clearer
Edit 2:
After Searching and screwing around i found 2 possible ways i might be able to do this
however both i can't find how to do it in VB.net
First
Look for AxAcroPDFLib.AxAcroPDF in available namespaces
found C# example but i don't know how to change it to Vb.net
C# - How to check if namespace, class or method exists in C#??
Second
Add Unhandled Exception Handler
also found a few examples but none seem to work
Any Chance anyone could direct me to a working example for either (or both) of these options
Manged to fin a working solution, doesn't work how i was originally thinking but it doe work just fine
i used the following code
Dim AdobeSoftwares As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("ADOBE")
If AdobeSoftwares Is Nothing Then
'MessageBox.Show("No Adobe Software")
Dim PdfDisplay As New PdfiumViewer.PdfViewer
PDFControl = "Pdfium"
Else
If Not Array.IndexOf(AdobeSoftwares.GetSubKeyNames, "Acrobat Reader") = -1 Then
'MessageBox.Show("Adobe Reader Installed")
Dim PdfDisplay As New AxAcroPDFLib.AxAcroPDF
PDFControl = "Acrobat"
Else
'MessageBox.Show("Adobe Reader Not Installed")
Dim PdfDisplay As New PdfiumViewer.PdfViewer
PDFControl = "Pdfium"
End If
End If
Then in my display code i just look to see what "PDFControl" is in use and run the relevant code to display in that display
So now if adobe reader is installed, I'll be using its control, and if it isn't I'll be using the free (but less featured) control to display PDF files
So hopefully if anyone else is looking at doing similar to me then they can

Close MS Project using VSTO

I have a VSTO on MS Project. I use VB.NET. What I need is when I press the button I created on the ribbon, it will perform some codes which will update the info of some task, however, I would need to close the MS Project automatically. I tried application.FileCloseEx(), but it only closes the file, the MS Project is still loaded. I need similar to clicking the x button of the window.
Thanks,
Gilbert
If your MS Project application object is represented by "appMSProject" then it's as simple as:
appMSProject.Quit
OR say in a macro running under Project:
Application.Quit
Here's how I do it in VBA from Excel or Access. As far as I can tell the objects & methods are the same in VB.NET. Bottom line is that I create an instance of the MS Project object which starts the app & opens a file, execute some work, close the file, then destroy the MS Project object by setting it to Nothing. That has the effect of closing the app. You can also use "appMSProject.Quit" followed by setting it to Nothing. Frankly the 2nd option looks more orderly & easier to understand in code. Anyway, here's a sample of the way I do it:
Dim appMSProject As MSProject.Application
Dim prjPrj As MSProject.Project
Dim strPrjFile As String
strPrjFile = "C:\where_is_my_file\file_name.mpp"
Set appMSProject = New MSProject.Application
appMSProject.FileOpenEx Name:=strPrjFile
Set prjPrj = appMSProject.ActiveProject
'''Do something in here with the prjPrj
'Close the file, in my case w/o saving
appMSProject.FileCloseEx pjDoNotSave
'Destroy the objects
Set prjPrj = Nothing
Set appMSProject = Nothing
FYI - In this example I'm doing background work so I don't show the app. I also use "early binding".
Here's an MSDN example that does show the app with more info on early -vs- late binding - https://msdn.microsoft.com/en-us/library/office/ff865152.aspx

Crystal report printing to wrong printer

I'm troubleshooting an issue with a VB.NET app that I inherited.
The following lines execute print operation:
Me.rptShippingLabel1.PrintOptions.PrinterName = "LabelPrinter"
Me.rptShippingLabel1.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape
Me.rptShippingLabel1.PrintToPrinter(Me.txtLabelQty.Text, False, 1, 1)
There is a Zebra ZDesign TLP2844 connected to workstations via direct USB and named LabelPrinter. However, despite target printer being specified in the code, that Zebra must be set as default printer in Windows, otherwise the job would go to any other printer set as default.
What's even more frustrating is that on some computers, with exactly the same configuration jobs go to correct printer but I can't identify controllable pattern.
Any suggestions why might that be?
Reports in question are disassociated from printer in Design>Page Settings.
Look into your report. In page settings see if report is optimized for display. If yes, uncheck it. If report is optimized for displaying only, PrinterOptions enumeration is being discarded. You could still assign to Printer name property in older framework but not anymore.
Try the following code
Dim rptShippingLabel1 As New CrystalReport1
Dim PrinterSettings1 As New Printing.PrinterSettings
Dim PageSettings1 As New Printing.PageSettings
'Replace it with your printer name
PrinterSettings1.PrinterName = "Microsoft XPS Document Writer"
rptShippingLabel1.PrintToPrinter(PrinterSettings1, PageSettings1, False)
to get the printer name, don't read it from rptShippingLabel1.PrintOptions.PrinterName it will show blank. Try reading from PrinterSettings1.PrinterName.
This is tested with Crystal Reports runtime 13.0.9