I'm using a userform to collect data and add it to an empty line in a workbook. Structure of code is as follows:
- Main sub
s_OpenWriteToTargetFileis called from userformmainForm. - It checks availability of the target workbook.
- It opens the target workbook.
- It calls sub "s_WriteLines". Everything is OK up to this point.
- Sub
s_WriteLinesshould load textbox values frommainForminto various variables and paste them into the target workbook.
For some reason, code execution jumps out of s_WriteLines as soon as it reaches With MainForm..., and it returns to the mother sub.
s_WriteLines sub
Sub s_WriteLines
Dim a,b as integer
With mainForm
a = .tb_a.Value
b = .tb_b.Value
End With
End Sub
I can't wrap my head around it. Does this have something to do with the modality of the userform?
Dim a,b as integeronly declaresb As Integerbut leavesa As Variantyou need to specify a type for every variable. - PᴇʜDim objThis as object: set objThis = mainForm. - Romcel GeluzOn Error Resume Nextsomewhere in the caller module AND not having mainForm as a valid object. Put this beforeWith mainFormto check:On Error Goto 0 : Debug.Print mainForm.Caption- AcsErno