Display text depending on combo box in a different form

shaneucc

Registered User.
Local time
Today, 23:13
Joined
Jul 25, 2013
Messages
28
I want to display the text from one combo in a text box in another form based on what's selected in a second combo box. The text box is in a different form from the combo boxes. Any idea what's wrong with this code?

Sub D_ComponentTypeCmb_Change()

If Me.D_ComponentNameCmb.Value = "Customise" Then
Forms!CustomComponentF!C_ComponentTxt.Value = Me.D_ComponentTypeCmb
Else
Forms!CustomComponentF!C_ComponentTxt.Value = ""
End If

End Sub
 
Have you tried your code in the After Update event of D_ComponentTypeCmb instead of the "On Change" event.
 
No luck I'm afraid
 
Try this..
Code:
Private Sub D_ComponentTypeCmb_AfterUpdate()
    MsgBox Me.D_ComponentNameCmb
End Sub
Post back what you get in the Message Box..
 
Try the following code in the After Update event
Code:
If 
Msgbox Me.D_ComponentNameCmb
Me.D_ComponentNameCmb.Value = "Customise" Then
Forms!CustomComponentF!C_ComponentTxt.Value = Me.D_ComponentTypeCmb
Else
Forms!CustomComponentF!C_ComponentTxt.Value = ""
End If
and select "Customise"
Does the msg box actually show: "Customise"
 
Try this..
Code:
Private Sub D_ComponentTypeCmb_AfterUpdate()
    MsgBox Me.D_ComponentNameCmb
End Sub
Post back what you get in the Message Box..

The message box displayed the text from D_ComponentNameCmb
 
Did you try stepping through the code? Have you tried Bob's code?
 
I'm not sure I understand Bob's code. It doesn't allow you to run it as it's not the correct format for an if statement.

What do you mean by stepping through it?
 
I have just noticed an error in the code that I posted earlier. It should have read:
Code:
Msgbox Me.D_ComponentNameCmb
If Me.D_ComponentNameCmb.Value = "Customise" Then
Forms!CustomComponentF!C_ComponentTxt.Value = Me.D_ComponentTypeCmb
Else
Forms!CustomComponentF!C_ComponentTxt.Value = ""
End If
However, what msg do you get with:
Code:
If Me.D_ComponentNameCmb.Value = "Customise" Then
Msgbox Me.D_ComponentTypeCmb
Forms!CustomComponentF!C_ComponentTxt.Value = Me.D_ComponentTypeCmb
Else
Forms!CustomComponentF!C_ComponentTxt.Value = ""
End If
Paul's suggestion of stepping through the code at runtime and checking values is really the way to go, IMHO.
 
To Step Through the code, do the following..

attachment.php


When you place/hover the mouse over the variables you will see what value it holds, and also how the Debugger is asserting the If statement..
 
However, what msg do you get with:
Code:
If Me.D_ComponentNameCmb.Value = "Customise" Then
Msgbox Me.D_ComponentTypeCmb
Forms!CustomComponentF!C_ComponentTxt.Value = Me.D_ComponentTypeCmb
Else
Forms!CustomComponentF!C_ComponentTxt.Value = ""
End If
Paul's suggestion of stepping through the code at runtime and checking values is really the way to go, IMHO.

This returns the text in D_ComponentTypeCmb in a message box. If appears that the problem is with the line
Code:
    If Me.D_ComponentNameCmb.Value = "Customise" Then
although I can't figure out why this would be.
 
So I take it you tried Stepping through? How do you recogonise that the If condition is the problem here?
 
I know it must be the If statement that's the problem because if I remove it and just use the code
Code:
Forms!CustomComponentF!C_ComponentTxt.Value = Me.D_ComponentTypeCmb
it works fine.
 
Which denotes the comparison is surely failing.. Can you please upload a Stripped down version of your DB?
 

Users who are viewing this thread

Back
Top Bottom