Hi
Just wondering how you go about passing a variable that has a value set within a procedure in the objects part of the project, to a userform.
I can pass variables from the userform to the procedure okay, but not the other way around.
I have tried declaring the variabe as Public (had to do this in both the form and in the general declarations above the procedure, otherwise I got a Variable Not Defined error), and making all my procedures public, but this doesn't seem to work.
Procedure in the Objects area:
Public Sub InvalidNum(Length, ContainerNum)
If (Length < 10) Or (Length > 11) Then
Rem the Batch ID entered is not long enough to be a valid one.
Rem User needs to correct before going further
frmInvalidNum.Show
If frmInvalidNum.Answer2 = 2 Then
Rem if the the user clicks Add this Batch ID, then continue with adding the batch
BatchID = ContainerNum
Exit Sub
ElseIf frmInvalidNum.Answer2 = 1 Then
Rem if the user clicks Re-enter, then go back to the Batch ID field to correct entry
Call Retry
End If
End If
End Sub
User Form:
Option Explicit
Dim Batch_ID As String
Public Answer2 As Integer
Private Sub cmdAddBatch_Click()
Answer2 = 2
Hide
End Sub
Private Sub cmdReenter_Click()
Answer2 = 1
Hide
End Sub
Private Sub UserForm_Activate()
frmInvalidNum.lblBatchID.Caption = ContainerNum
End Sub
I want to pass the value of the variable ContainerNum from the procdure to the form.
Cheers
Anna
Just wondering how you go about passing a variable that has a value set within a procedure in the objects part of the project, to a userform.
I can pass variables from the userform to the procedure okay, but not the other way around.
I have tried declaring the variabe as Public (had to do this in both the form and in the general declarations above the procedure, otherwise I got a Variable Not Defined error), and making all my procedures public, but this doesn't seem to work.
Procedure in the Objects area:
Public Sub InvalidNum(Length, ContainerNum)
If (Length < 10) Or (Length > 11) Then
Rem the Batch ID entered is not long enough to be a valid one.
Rem User needs to correct before going further
frmInvalidNum.Show
If frmInvalidNum.Answer2 = 2 Then
Rem if the the user clicks Add this Batch ID, then continue with adding the batch
BatchID = ContainerNum
Exit Sub
ElseIf frmInvalidNum.Answer2 = 1 Then
Rem if the user clicks Re-enter, then go back to the Batch ID field to correct entry
Call Retry
End If
End If
End Sub
User Form:
Option Explicit
Dim Batch_ID As String
Public Answer2 As Integer
Private Sub cmdAddBatch_Click()
Answer2 = 2
Hide
End Sub
Private Sub cmdReenter_Click()
Answer2 = 1
Hide
End Sub
Private Sub UserForm_Activate()
frmInvalidNum.lblBatchID.Caption = ContainerNum
End Sub
I want to pass the value of the variable ContainerNum from the procdure to the form.
Cheers
Anna