By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,784 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

How to make to click in button and open form releated in value in combox in Ms Access

P: 4
Hi, I have code which should open a form to specific value in combobox. But there is a mistake, because only show message "I don't know what to do with this combobox value". Maybe I should apply filter? But I don't know how? Could you please help me?

My code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub ComboBoxColor_AfterUpdate()
  2.  
  3.     On Error GoTo Err_Handler
  4.  
  5.     Dim strForm As String
  6.  
  7.     Select Case ComboBoxColor.Value
  8.  
  9.         Case "Color1"
  10.             strForm = "Form1"
  11.  
  12.         Case "Color2"
  13.             strForm = "Form2"
  14.  
  15.         Case "Color3"
  16.             strForm = "Form3"
  17.  
  18.         Case Else
  19.             MsgBox "I don't know what to do with this combobox value"
  20.             GoTo Exit_Sub
  21.     End Select
  22.  
  23.     DoCmd.OpenForm strForm, acNormal
  24.  
  25. Exit_Sub:
  26.     Exit Sub
  27.  
  28. Err_Handler:
  29.     MsgBox Err.Description, vbExclamation, "Error " & Err.Number
  30.     Resume Exit_Sub
  31.  
  32. End Sub
Feb 23 '19 #1
Share this Question
Share on Google+
6 Replies


Nauticalgent
P: 89
With the code, if the combo box value is anything other than Color1, Color2 or Color3, you will get that message

If your combo box values are indeed correct, I would look at the data source for the combo box, particularly the bound column. I suspect the actual value is a ID number and not literal text.
Feb 23 '19 #2

twinnyfo
Expert Mod 2.5K+
P: 3,184
Yes, NauticalGent is on the right track. What is the RowSource for your combo box? This will tell us much for troubleshooting.
Feb 24 '19 #3

Expert 100+
P: 1,031
May I suggest to change line #19 to
Expand|Select|Wrap|Line Numbers
  1. MsgBox "I don't know what to do with this combobox value [" + ComboBoxColor.Value +"]"
Above is step 1 in debugging, which is ALWAYS show the value you are testing against. It will give you more info ALWAYS.

This will show what value you are checking for, which good give a clue about why you are always getting "I don't know "
Feb 24 '19 #4

P: 4
Thank you for your message. So I want to select a value in the combo box, and then open the form with a separate command button and the open form should be different depending on the chosen value in the second combobox.

I created comboxes with macros:

first combobox RowSource
Expand|Select|Wrap|Line Numbers
  1. SELECT [DANE].[Identyfikator], [DANE].[Projekt] FROM DANE;
second combobox RowSource
Expand|Select|Wrap|Line Numbers
  1. SELECT [TestyDane].[Id], [TestyDane].[Test] FROM TestyDane;
My change code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Polecenie126_Click()
  2. On Error GoTo Err_Handler
  3.     Dim strForm As String
  4.  
  5.     Select Case txtTest.Value
  6.  
  7.         Case "[Gloss]"
  8.             strForm = "Test1"
  9.         Case "[Coolant]"
  10.             strForm = "Test2"
  11.         Case Else
  12.             MsgBox "I don't know what to do with this combobox value"
  13.             GoTo Exit_Sub
  14.     End Select
  15.  
  16.     DoCmd.OpenForm strForm, acNormal
  17.  
  18. Exit_Sub:
  19.     Exit Sub
  20.  
  21. Err_Handler:
  22.     MsgBox Err.Description, vbExclamation, "Error " & Err.Number
  23.     Resume Exit_Sub
  24. End Sub
What should the code look like to work in the correct way?
Feb 24 '19 #5

twinnyfo
Expert Mod 2.5K+
P: 3,184
As mentioned before, because you are using the value of Projekt or Test, you actually need to use the value for Identyfikator or Id when determining which form to open.

By simply displaying the value of the combo box in your I dont know what to do message (as mentioned in a previous post), you would have been able to see what you are using in your variables.
Feb 24 '19 #6

Expert 100+
P: 1,031
Maybe I was not clear, so I am copying a bigger piece of your code wit my proposed change
Expand|Select|Wrap|Line Numbers
  1. Select Case txtTest.Value
  2.  
  3.         Case "[Gloss]"
  4.             strForm = "Test1"
  5.         Case "[Coolant]"
  6.             strForm = "Test2"
  7.         Case Else
  8.             MsgBox "I don't know what to do with this combobox value [" + txtTest.Value + "]"
  9.             GoTo Exit_Sub
  10.     End Select
The change is in line #8

After this you should no longer get messages like:
"I don't know what to do with this combobox value"

but you should see a message like:
"I don't know what to do with this combobox value [ABC]"
where "ABC" is the code you did not test against, because its different than "[Gloss]" or "[Coolant]".
The '[' and ']' are always added just to be sure if there s a leading, or trailing space in your field.
Feb 27 '19 #7

Post your reply

Sign in to post your reply or Sign up for a free account.