I have a userform (frmMatrix) where the user enters the current Heat Index and Population of Interest and is returned with a statement of recommended protective measures. Next, they are asked if they would like to make a record of these protective measures in my Data Entry form (frmForm). Upon clicking yes, I would like my Data Entry form to display with the "Heat Index" and "Population of Interest" fields filled with the values entered by the user in the form frmMatrix.
I am able to successfully open the Data Entry form, but the values loaded into the "Heat Index" and "Population of Interest" fields are those entered by the user *two* entries ago.
For example, suppose the user makes the following consecutive entries into frmMatrix:
#1: "83" and "Athletes"
#2: "85" and "Children"
#3: "87" and "Outdoor Workers"
When the user answers "Yes" to open the Data Entry form after making entry #2, the Data Entry form will display with the values "83" and "Athletes" in the Heat Index and Population of Interest fields (the responses given in example #1).
After making entry #3 and selecting "Yes", the Data Entry form will open with the values from entry #2 ("85" and "Children").
Why might this be happening? It seems there's an issue passing the updated variables for Heat Index and Population of Interest into the Data Entry form. I've copied my code below.
pictures of forms if useful:
frm Matrix:
frmForm (Data Entry form):
I am able to successfully open the Data Entry form, but the values loaded into the "Heat Index" and "Population of Interest" fields are those entered by the user *two* entries ago.
For example, suppose the user makes the following consecutive entries into frmMatrix:
#1: "83" and "Athletes"
#2: "85" and "Children"
#3: "87" and "Outdoor Workers"
When the user answers "Yes" to open the Data Entry form after making entry #2, the Data Entry form will display with the values "83" and "Athletes" in the Heat Index and Population of Interest fields (the responses given in example #1).
After making entry #3 and selecting "Yes", the Data Entry form will open with the values from entry #2 ("85" and "Children").
Why might this be happening? It seems there's an issue passing the updated variables for Heat Index and Population of Interest into the Data Entry form. I've copied my code below.
VBA Code:
Option Explicit
Public index As Integer
Public category As String
Public population As String
Private Sub cmdGo_Click()
If ValidateMatrixEntries() = True Then
index = frmMatrix.txtIndex.Object.Value
population = frmMatrix.cmbPopulation.Object.Value
'--------------------------------------------------------------------------------------------
'Heat Stress Category 1
If index < 80 Then
category = "Category 1"
'(nonrelevant code follows for outputting protective measures)
'--------------------------------------------------------------------------------------------------
Dim AnswerYes As String
Dim AnswerNo As String
AnswerYes = MsgBox("Would you like to record these actions in the log?", vbQuestion + vbYesNo, "Record Entry")
If AnswerYes = vbYes Then
Call Preset_Form
Unload frmMatrix
Else
Unload frmMatrix
End If
End If
End Sub
Public Sub Preset_Form()
frmForm.Show
frmForm.txtIndex.Value = index
frmForm.cmbPopulation.Value = population
frmForm.cmbAction.Value = category
End Sub
pictures of forms if useful:
frm Matrix:
frmForm (Data Entry form):