ComboBox and DLookup Issue

F

FA

Hi All
On my subform i have a combo box called Finding Combo, the following
are the codes in after update event of the combo box,
Me.FINDG_STD_ID = DLookup("[FINDG_STD_ID]", "dbo_STD_FINDG",
"[FINDG_STD_ID] = " & Me.Combo54)
Me.FINDG_NME = DLookup("[FINDG_NME]", "dbo_STD_FINDG", "[FINDG_STD_ID]
= " & Me.Combo54)
Me.OWASP_CLS = DLookup("[OWASP_CLS]", "dbo_STD_FINDG", "[FINDG_STD_ID]
= " & Me.Combo54)
Me.SANS_TOP10 = DLookup("[SANS_TOP10]", "dbo_STD_FINDG",
"[FINDG_STD_ID] = " & Me.Combo54)
Me.CVE_NO = DLookup("[CVE_NO]", "dbo_STD_FINDG", "[FINDG_STD_ID] = " &
Me.Combo54)
Me.STD_RSK = DLookup("[STD_RSK]", "dbo_STD_FINDG", "[FINDG_STD_ID] = "
& Me.Combo54)

Its populating the values of Me.STD_RSK from a table.
Here is my problem, I have another combo box called CboRskLVL, I want
to prepopulate that combo box according the value in Me.STD_RSK. Since
CboRskLVL is not a field in table dbo STD_FINDING otherwise i could do
something like that for that combo box too.
Here is my code, Since this form is a subform i can not put it in the
form load event because it will only do it once and after someone
change the record from the combo box, it will not work because it will
not load again.

If Me.STD_RSK.Value = "High" Then
Me.FINDG_RSK_LVL_ID.Value = Me.CboRskLVL.ItemData(3)
End If
If Me.STD_RSK.Value = "Medium" Then
Me.FINDG_RSK_LVL_ID.Value = Me.CboRskLVL.ItemData(2)
End If
If Me.STD_RSK.Value = "Low" Then
Me.FINDG_RSK_LVL_ID.Value = Me.CboRskLVL.ItemData(1)
End If
I want the value of CboRskLVL change after STD_RSK gets a new value
which happens after the user select something in the Combo54 and it
DLookup the value for STD_RSK. I want to know where should i put this
code so everything STD_RSK change, CboRskLVL change

Can some help me please
 
G

George Nicholson

1) Put your 2nd block of code in a separate sub procedure. Lets call it
"UpdateRiskLevel"
2) Call UpdateRiskLevel from every place Std_Risk can change: Form.Current,
Std_Risk.AfterUpdate, Finding.AfterUpdate, etc.

Keep in mind that changes made to controls via code won't trigger the
AfterUpdate events of those controls. That's why you need to call
UpdateRiskLevel (or Std_Risk_AfterUpdate which then calls UpdateRiskLevel)
when you change Std_Risk from Finding.AfterUpdate (your 1st block of code).

HTH,
 
F

FA

i have this code in the subform Load, Current, Activate, Afterinsert
Event procdures as well as after the Finding.AfterUpdate Procdure, it
still doesnt work after i select a different recode in the combo box
Combo54.
It works in the first time wheni open the form but when i change the
record it just stays unchanged.
If Me.STD_RSK.Value = "High" Then
Me.FINDG_RSK_LVL_ID.Value = Me.CboRskLVL.ItemData(3)
End If
If Me.STD_RSK.Value = "Medium" Then
Me.FINDG_RSK_LVL_ID.Value = Me.CboRskLVL.ItemData(2)
End If
If Me.STD_RSK.Value = "Low" Then
Me.FINDG_RSK_LVL_ID.Value = Me.CboRskLVL.ItemData(1)
End If
 
B

Banaticus

Can you do Else IF or otherwise stack the IF, something like
If Me.STD_RSK.Value = "High" Then
Me.FINDG_RSK_LVL_ID.Value = Me.CboRskLVL.ItemData(3)
If Me.STD_RSK.Value = "Medium" Then
Me.FINDG_RSK_LVL_ID.Value = Me.CboRskLVL.ItemData(2)
If Me.STD_RSK.Value = "Low" Then
Me.FINDG_RSK_LVL_ID.Value = Me.CboRskLVL.ItemData(1)
End If
End If
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top