Originally Posted by
Dave14867
Hello all,
I am trying to use a Case Statement which I haven't used in the past so I am not sure I am doing it correctly. I have the following code,
Private Sub CmdAddToInventory_Click()On Error GoTo CmdAddToInventory_Click_Err
Dim Part As String
Part = CmbPNSelect.Column(1)
Select Case CmbPNSelect()
Case Part = "M26617"
MsgBox "Found M26617"
End Select
I have a stop put in at "End Select" so I can see what "Part" is equal to and it is equal to "M26617" however I am not getting the message box as expected. Can someone tell me what I am missing or have incorrect? This is just a test at this point and once I get it working I want to put in a lot of other case possibilities.
Thanks in advance
Dave
Dave
When posting code please use the code tags and indentation.
You are not showing the complete code.
In the following code I have changed the name of your variable and added what I think should be the rest of the code that is missing.
Code:
Private Sub CmdAddToInventory_Click()
On Error GoTo CmdAddToInventory_Click_Error
Dim strPart As String
strPart = CmbPNSelect.Column(1)
Select Case CmbPNSelect()
Case strPart = "M26617"
MsgBox "Found M26617"
End Select
CmdAddToInventory_Click_Exit:
Exit Sub
CmdAddToInventory_Click_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in Form: " & Me.Name & " in procedure CmdAddToInventory_Click, line " & Erl & "."
Resume CmdAddToInventory_Click_Exit:
End Sub