I have several forms, and there are several lines of code used to call and place each one. Instead of replicating these lines of code for each form, I want to use a subroutine simply to load and place a form. This code works:
Sub LoadForm_BulletBeginningEmphasis()
Load formBulletBeginningEmphasis
formBulletBeginningEmphasis.Show
formBulletBeginningEmphasis.StartUpPosition = 0
formBulletBeginningEmphasis.Left = Application.Left + (0.5 * Application.Width) - (0.5 * formBulletBeginningEmphasis.Width)
formBulletBeginningEmphasis.Top = Application.Top + (0.5 * Application.Height) - (0.5 * formBulletBeginningEmphasis.Height)
End Sub
What I want, though, is for this code to work, instead:
Public Sub LoadAndShowForms(ByVal formName As Object)
Load formName
formName.Show
formName.StartUpPosition = 0
formName.Left = Application.Left + (0.5 * Application.Width) - (0.5 * formName.Width)
formName.Top = Application.Top + (0.5 * Application.Height) - (0.5 * formName.Height)
End Sub
Sub LoadForm_BulletBeginningEmphasis()
Call LoadAndShowForms(formBulletBeginningEmphasis)
End Sub
The problem is that when I execute the second set of code lines, they work and the form works, but when the form disappears, VBA throws an error:
What's going on here? Why is the second version working but throwing an error?