Local and Public Variables

ismailr

Registered User.
Local time
Today, 11:07
Joined
Oct 16, 2015
Messages
31
Hello,

This is my first question on this forum. I got good help from time to time by reviewing others threads and issues.

I have problem to manage the values from two different forms.
On first form we calculated results from two textboxes and store into a public variable. On this form there is a button which close the current active form and open second form . I need to show the result of first form on the second form.
On codes available on form ‘FirstForm’

Option Compare Database
Public results As Integer

Private Sub txtFirst_AfterUpdate()
Me.lblResult.Caption = Val(Me.txtFirst.Value) + IIf(Me.txtSecond = Null, 0, Val(Me.txtSecond.Value))
results = Me.lblResult.Caption
End Sub

Private Sub txtSecond_AfterUpdate()
Me.lblResult.Caption = Val(Me.txtFirst.Value) + Val(Me.txtSecond.Value)
results = Me.lblResult.Caption
End Sub

Private Sub cmdNext_Click()
DoCmd.Close , "FirstForm"
DoCmd.OpenForm "Second"
End Sub

On second form OnLoad event is;
Option Compare Database

Private Sub Form_Load()
Me.lblFromFirstForm.Caption = results
End Sub

If I use Me.lblFromFirstForm.Caption = Forms!FirstForm.lblResult.Caption on second form I get the value from the first form. But I wanted to manage it through variables. Please advice.
Thanks
Ismail

 
I think you need to declare the variable result in a General module rather than in the module of a form.
 
Thanks Bob for reply.

The variable results is already declare in General Section. please see the attachment.
thanks
Ismail
 

Attachments

Thanks Bob, you are correct.
I define now under module and able to get the expected output.
thanks

Ismail
 

Users who are viewing this thread

Back
Top Bottom