Trouble pre-setting userform values based off user input

gc2001

New Member
Joined
Apr 2, 2024
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hello,

I currently have a functioning Data Entry form (frmForm) with a combination of text boxes and combo boxes.

I also have a separate user-form seen below (frmMatrix) where the user enters the current heat index and selects a Population of Interest, and is then returned with a message box of recommended protective measures.
1712073704873.png


I have another message box that follows, asking if the user would like to make a record in my Data Entry form (frmForm). Upon selecting yes, the Data Entry form is opened for the user.

What I am trying to accomplish is to have the "Heat Index" and "Population of Interest" fields automatically filled with the responses previously given by the user as seen below. I am running into an issue where the presetting of values is one step behind and uses the Heat Index and Population values from 2 entries ago, not the last one.

I've verified that my "index" and "population" variables are correctly updating each time the frmMatrix form is used, so something seems to be going wrong when presetting the values in frmForm. I'm not sure if maybe I need to add code to erase the previous values or something.



Here is my code:
1712073807904.png

1712073579183.png





1712073641423.png



Thanks in advance for the help.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Pics of code are of little use (at least to me). Far too small in the post; requires flipping back and forth between browser tabs, can't copy so requires re-typing, etc. etc.
Best is to copy your code, click the vba button on posting toolbar to insert code tags, then paste between those tags. Code gets nicely formatted and maintains indentation. Not saying I can help with the issue; just that I can help you help others to help you.
 
Upvote 0
VBA Code:
Private Sub cmdGo_Click()

    
    
    Dim index As Integer
    Dim category As String
    Dim population As String
    
    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"
        
            MsgBox "You are in Heat Stress Action Category 1.", vbOKOnly, "Category"
    
            If population = "Athletes" Then
            
                MsgBox "Follow normal practice and play procedures.", vbOKOnly, "Recommendation"
            
            ElseIf population = "Pregnant Individuals" Then
            
                MsgBox "Avoid strenuous activity.", vbOKOnly, "Recommendation"
            
            Else
            
                MsgBox "No additional action necessary.", vbOKOnly, "Recommendation"
            
            End If
    '----------------------------------------------------------------------------------------------
    
    'Heat Stress Category 2
        ElseIf 80 <= index And index < 90 Then
        
            category = "Category 2"
        
            MsgBox "You are in Heat Stress Action Category 2.", vbOKOnly, "Category"
            
            If population = "Indoor Operations" Then
                
                MsgBox "No additional action necessary.", vbOKOnly, "Recommendation"
            
            ElseIf population = "Athletes" Then
            
                MsgBox "Recommended minimum of three 4- minute breaks along with 32 ounces of water intake each hour.", vbOKOnly, "Recommendation"
            
            ElseIf population = "Children" Then
            
                MsgBox "Stay with responsible adults/guardians who can provide heat relief options when necessary.", vbOKOnly, "Recommendation"
            
            ElseIf population = "Student Dorm Residents with no HVAC" Then
            
                MsgBox "Open windows at night when the air temperature is lower to increase ventilation." & vbNewLine & vbNewLine & "Place a box fan in the opening of the dorm window to increase ventilation if possible.", vbOKOnly, "Recommendation"
            
            'ElseIf population = "Older Adults" Then
            
                MsgBox "No additional action necessary.", vbOKOnly, "Recommendation"
            
            'ElseIf population = "Individuals with Chronic Conditions" Then
            
                MsgBox "No additional action necessary.", vbOKOnly, "Recommendation"
            
            'ElseIf population = "Pregnant Individuals" Then
            
                MsgBox "No additional action necessary.", vbOKOnly, "Recommendation"
            
            'ElseIf population = "Outdoor Workers" Then
            
                MsgBox "No additional action necessary.", vbOKOnly, "Recommendation"
            
            'ElseIf population = "Individuals with Disabilities" Then
            
                MsgBox "No additional action necessary.", vbOKOnly, "Recommendation"
            
            End If
    '----------------------------------------------------------------------------------------------
    
    'Heat Stress Category 3
        ElseIf 90 <= index And index < 103 Then
        
            category = "Category 3"
        
            MsgBox "You are in Heat Stress Action Category 3.", vbOKOnly, "Category"
            
    '----------------------------------------------------------------------------------------------
    
    'Heat Stress Category 4
        ElseIf 103 <= index And index < 125 Then
        
            category = "Category 4"
        
            MsgBox "You are in Heat Stress Action Category 4.", vbOKOnly, "Category"
            
    '----------------------------------------------------------------------------------------------
    
    'Heat Stress Category 5
        Else 'index is 125+
        
            category = "Category 5"
        
            MsgBox "You are in Heat Stress Action Category 5.", vbOKOnly, "Category"
    
        End If
        
    '----------------------------------------------------------------------------------------------
        
    
        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
        
            
            frmForm.Show
            Call Reset
            With frmForm.txtIndex
                .Value = index
            End With
            
            With frmForm.cmbPopulation
                .Value = population
            End With
                
            With frmForm.cmbAction
                .Value = category
            End With
        
        Else
        
            Exit Sub
            
        End If
        
        
    
    End If


End Sub
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,107
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top