UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Select Case Format, Access 2016    
 
   
Consonanza
post Jun 1 2020, 07:04 AM
Post#1



Posts: 179
Joined: 1-June 10



I often have trouble with my use of Select Case. Here's another example I am struggling with.

I have a combo box which when a choice is made should update a separate field based on the value chosen.

CODE
Select Case Me!cboFormat
Case Is = "CD" Or "2CD" Or "3CD"
Me!fldClass = "C"
Case is ="LP" or "2LP" or "3LP"
Me!fldClass = "L"
etc
etc
End select

In this example, if I select any CD value, I get a type mismatch error. Both
fldFormat (for cboFormat) and fldClass are Short text fields.

Go to the top of the page
 
missinglinq
post Jun 1 2020, 07:16 AM
Post#2



Posts: 4,705
Joined: 11-November 02



Try this
CODE
Select Case Me!cboFormat
  Case "CD", "2CD", "3CD"
    Me!fldClass = "C"
  Case "LP", "2LP", "3LP"
    Me!fldClass = "L"
'''etc
'''etc
End select

Linq ;0)>

--------------------
BTW...The Monkey is laughing at me...not at any other poster!

The problem with making anything foolproof...is that fools are so darn ingenious!

All posts/responses based on Access 2003/2007
Go to the top of the page
 
pere_de_chipstic...
post Jun 1 2020, 07:18 AM
Post#3


UtterAccess Editor
Posts: 10,669
Joined: 8-November 07
From: South coast, England


What line is the code failing on?

The Select Case could be written as:

CODE
Select Case NZ(Me!cboFormat,"")
Case "CD", "2CD", "3CD"
     Me!fldClass = "C"
Case "LP", "2LP", "3LP"
     Me!fldClass = "L"
etc
etc
End select

I've changed the Select Case line to Select Case NZ(Me!cboFormat,"") as cboFormat could potentially be null.



--------------------
Warm regards
Bernie
Go to the top of the page
 
Consonanza
post Jun 1 2020, 08:08 AM
Post#4



Posts: 179
Joined: 1-June 10



Thanks missinglinq! A permutation I hadn't tried and it worked a treat!

@Bernie, thanks - a useful tip but in this case nz not needed as the Select Case
is in the afterupdate event of the combo box, so will by definition contain a value.
Go to the top of the page
 
pere_de_chipstic...
post Jun 1 2020, 08:23 AM
Post#5


UtterAccess Editor
Posts: 10,669
Joined: 8-November 07
From: South coast, England


HI

QUOTE
@Bernie, thanks - a useful tip but in this case nz not needed as the Select Case
is in the afterupdate event of the combo box, so will by definition contain a value.


I'd agree if the control was a list box, however if you delete the entry in a combo box then the after update event will fire and the combo box will return a null value.

--------------------
Warm regards
Bernie
Go to the top of the page
 
Consonanza
post Jun 1 2020, 08:28 AM
Post#6



Posts: 179
Joined: 1-June 10



Point taken. An unlikely event but to be safe, I'll add the nz. Thanks.
Go to the top of the page
 
pere_de_chipstic...
post Jun 1 2020, 08:38 AM
Post#7


UtterAccess Editor
Posts: 10,669
Joined: 8-November 07
From: South coast, England


yw.gif

--------------------
Warm regards
Bernie
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    16th July 2020 - 08:57 AM