How to set Form1.ControlBox=TRUE from Form2 - vba

I receive 424 run-time error: "Object required".
Form1.ControlBox1 = True
sub Form1_Load() is "Public".
Thanks a lot

You need to do the following:
Forms!Form1.Form.ControlBox = True

Related

Automatically re-initialize VBA global variables after a run-time error

Question #1: Does Public myGobalVar As Integer need to be re-defined when a run-time error occurs?
Question #2: How do I automatically re-initialize my gobal variables whenever a run-time error occurs in the code?
Question #3: Would this error handling routine fail when dealing with unforeseen scenarios? How do I make it more fool-proof or robust?
Please refer to the pseudo code below.
''' Question #1: Does Public myGobalVar As Integer need to be re-defined when a run-time error occurs?
Public myGobalVar As Integer
Sub Application_Startup()
Call InitializeGobalVar()
End Sub
Sub InitializeGobalVar()
myGobalVar = 3
End Sub
Sub One_in_many_mySubs()
On Error Goto ErrHandler_myGobalVar
Dim objApp as Outlook.Application
Set objApp as Application
msgbox myGlobalVar
' erroneous event may occur somewhere in the code
Err.Clear
' skip ErrHandler_myGobalVar and exit sub after set objApp = Nothing
ErrHandler_myGobalVar:
if Err.number <> 0 then
''' Question #2: How do I automatically restart InitializeGobalVar whenever a run-time error occurs in the code?
Call InitializeGobalVar
MsgBox Err.Description
end if
Set objApp = Nothing
End Sub

VBA - Cancelling Dialog Box Run-time error 1004

I am attempting to have my end sub when I click cancel. However, I am getting a Run-Time Error when I do so.
I am just trying to close the dialog box which I did with an Else: Exit Sub statement. However, it still shows the Run-Time Error, while it should just exit sub.
This was a simple fix of just adding an ErrorHandler like so:
Public Sub Run_Split()
On Error GoTo ErrHandler
'Call Private Subs
Exit Sub
ErrHandler:
MsgBox "User Cancelled Program", vbCritical
End Sub
Thank you to everyone that has helped me on this site in the past, your help as allowed me to be somewhat self taught in VBA and I was able to solve this without asking for assistance.

Invalid Use Of Property Error. What am I missing?

I have a UserForm with two options Budget or Actual. If I select Actual the code works and Calls the Sub Routine Actual however if I select Budget I receive the error Invalid Use Of Property at the line Call Budget.
Option Explicit
Private Sub Budget_Click()
Call Budget
End Sub
Private Sub OptionButtonActual_Click()
Call Actual
End Sub
The Budget Sub Routine
Sub Budget()
Dim sys As Object
'Check to see if session is open
Set sys = CreateObject("BZWhll.WhllObj")
ResultCode = sys.Connect("B")
If (ResultCode) Then
MsgBox "UNABLE TO CONNECT TO SESSION!"
MsgBox "MACRO STOPPED!"
GoTo endM
End If
sys.Disconnect
X203BudgetExtract
endM:
End Sub
I changed the name of the option button to:-
OptionButtonBudget and now my code works!

trouble displaying custom VBA error description with Err.raise when using callByName

I have a Form in Access 2016 in Windows 10.
It has a function named e and a Form_Load event procedure like below:
Public Function e()
Err.Raise 1000, Description:="custom description"
End Function
Private Sub Form_Load()
On Error GoTo errorhandler
e
Exit Sub
errorhandler:
MsgBox (Err.Description)
End Sub
The e function raises an error with a custom description which is catched by the error handler and the message box shows:
custom description
Thus far there is no problem!
But if I call e using CallByName Me, "e", VbMethod then I get the default error description and message box shows:
Application-defind or object-defind error
Is there any workaround to call my function by name and also be able to handle errors and get custom error descriptions?

How to get date clicked on monthview to my textbox on userform?

Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
Txt_Prod_Loc_Date.Value = MonthView1.Value
Unload Me
End Sub
Private Sub FrmCalendar_Initialize()
Unload Me
End Sub
I also tried Txt_Prod_Loc_Date.Value= DateClicked. But I see a " runtime error 424, object required
Thanks
You can use both; MonthView1.Value or DateClicked. The problem is not because of that :)
BTW why do you have Unload Me in FrmCalendar_Initialize()? That would give you a Run Time Error 91. Object Variable or With block variable Not set
You are getting Runtime error 424, object required because it could not find the Txt_Prod_Loc_Date control on your userform.
If that control is in the worksheet then use it like this
Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
Sheet1.TextBox1.Value = MonthView1.Value
End Sub
If that control is in some other form (say Userform1) then use it like this
Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
UserForm1.Txt_Prod_Loc_Date.Value = MonthView1.Value
End Sub