473,325 Members | 2,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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

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
6 1786
Nauticalgent
100 64KB
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
3,653 Expert Mod 2GB
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
Luuk
1,047 Expert 1GB
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
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
3,653 Expert Mod 2GB
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 don’t 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
Luuk
1,047 Expert 1GB
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

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

Similar topics

1
by: Dalan | last post by:
I probably just need a simple piece of code to do this as the couple tried so far have failed. I created a new Access 97 Form Filter (frmFilterForm) which displays most of the key data fields from...
1
by: P | last post by:
Hi, Access 2002. I am trying to use the PrintOut function to print the current record of the current open form in landscape format to the default Windows printer. Any suggestion on how to set...
4
by: jaYPee | last post by:
I know how to open a form from another form. Say open form2 from form1 using a command button. But my problem is everytime I clicked the button it open again another instance of that form. ...
3
by: dannyf | last post by:
I have an access database that I need to open scanned jpegs from. I don't care if it opens "in" access or if it just invokes the native application for that file type. I need the button to look at...
3
by: jakeesgirl | last post by:
I am developing a program in C# Visual Studio and I have a form that is created when a button is clicked on another form. This new form comes up and immediately, a function is called and executed...
3
by: vidhyapriya | last post by:
Hi all I am developing windows application using vb.net.I want to pass values to open form.I am opening only one form when user click the buttons several times.Useing delegate i am passing...
5
by: billa856 | last post by:
Hi, My project is in MS Access 2002. In that I want to open one form multiple times. I put one button on my main form. Now whenever I click on that button than form will be open. Now when I...
2
by: Joergen Bech | last post by:
Hope someone has a solution or some suggestions for this. This cannot be right?!? Problem: I have multiple non-modal forms open at the same time. One or more of these forms have a...
2
by: dcharles | last post by:
Is there a way to open another form using info from an already existing one? For example, I have a form which lists companies and it has an employee subform (which lists a query output) on the same...
1
by: Bob Carter | last post by:
All, I have a Access *.mde application that I cannot make changes to, and need to draw data from a open form to a second Access application that will print labels. Any suggestions on how to pick...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.