Multiple if formulaes in macro

Markus_87

New Member
Joined
Mar 29, 2011
Messages
12
Hi all,

Bit of a beginner so please ignora my stupidity

I have asigned a macro to an autoshape (just to create a button) to print to a virtual printer. which works fine but i'm trying to ensure users fill in certain forms before it lets them go ahead. This is the code I have so far


Sub macro1()
If TextBox28.Text = "" Then
MsgBox "Please enter a Date before continuing", vbInformation, "Alert"
Else
If TextBox2.Text = "" Then
MsgBox "Please choose AM or PM before continuing", vbInformation, "Alert"
Else
If TextBox13.Text = "" Then
MsgBox "Please enter the 'Anaesthetist Name/Initial' field before continuing", vbInformation, "Alert"
Else
Range("I32").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
MsgBox "Your form has been submitted", vbInformation, "Confirmation"
End If
End If
End If

End Sub

I keep getting a Run-Time error '424': Object Required

Any help would be appreciated

Thanks
Mark
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Hi. Try

Code:
Sub macro1()
If TextBox28.Text = "" Then
MsgBox "Please enter a Date before continuing", vbInformation, "Alert"
End If
If TextBox2.Text = "" Then
MsgBox "Please choose AM or PM before continuing", vbInformation, "Alert"
End If
If TextBox13.Text = "" Then
MsgBox "Please enter the 'Anaesthetist Name/Initial' field before continuing", vbInformation, "Alert"
End If
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
MsgBox "Your form has been submitted", vbInformation, "Confirmation"

End Sub
 
Upvote 0
Sorry my mistake initial code did work as did yours but i was putting it in the wrong place. in the module section where i originally recorded the macro when it should have been under sheet1 with the user code.

See I said I was stupid

Many thanks anyway
 
Upvote 0
If only it was that simple

I've now realised that this code works great but it always choses the default printer. I need it to print to a different one in the list as I cant go round setting all the users default printers to the virtual one that i need to use for this.

Any ideas how to incorporate it in this code?

Sub macro1()
If TextBox13.Text = "" Then
MsgBox "Please enter the 'Anaesthetist Name/Initial' field before continuing", vbInformation, "Alert"
Else
If TextBox28.Text = "" Then
MsgBox "Please enter a Date before continuing", vbInformation, "Alert"
Else
If TextBox2.Text = "" Then
MsgBox "Please choose AM or PM before continuing", vbInformation, "Alert"
Else
Range("I32").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
MsgBox "Your form has been submitted", vbInformation, "Confirmation"
End If
End If
End If
End Sub
 
Upvote 0
Perhaps replace

Code:
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

with

Code:
Application.Dialogs(xlDialogPrint).Show
 
Upvote 0
Again VOG i'm asking for help before i've even looked properly i'm sorry.

All i need to add was the line in red below

Sub macro1()
If TextBox13.Text = "" Then
MsgBox "Please enter the 'Anaesthetist Name/Initial' field before continuing", vbInformation, "Alert"
Else
If TextBox28.Text = "" Then
MsgBox "Please enter a Date before continuing", vbInformation, "Alert"
Else
If TextBox2.Text = "" Then
MsgBox "Please choose AM or PM before continuing", vbInformation, "Alert"
Else
Range("I32").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:="name of printer", Collate:=True
MsgBox "Your form has been submitted", vbInformation, "Confirmation"
End If
End If
End If
End Sub

Many thanks again
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,729
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top