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

Select Case in a Loop

P: 10
I want to use select case in a loop as under:
Expand|Select|Wrap|Line Numbers
  1. Dim i As Integer
  2. i = 1
  3. While i < 6
  4.     Select Case Field1
  5.         Case "Title"
  6.             strFld(i) = "([Title] & ': ' & [Subtitle])"
  7.         Case "Author"
  8.             strFld(i) = "([AUTHOR] & ', ' & [SUBAUTHOR])"
  9.         Case "Subject"
  10.             strFld(i) = "Subject"
  11.         Case "Publisher"
  12.             strFld(i) = "Publisher"
  13.         Case "Year of Publication"
  14.             strFld(i) = "Year"
  15.         Case "Call No"
  16.             strFld(i) = "([DDC_NO] & ' ' & [Auth_MARK])"
  17.         Case "Acc No"
  18.             strFld(i) = "ACCNO"
  19.     End Select
  20.     i = i + 1
  21. Wend
  22.  
  23.  
can I use the line no 4 code as:
Select Case Field1, Field2, Field3, Field4, Field5

Note: Field(5) is string variable and strFld(5) is also a string variable
Sep 12 '07 #1
Share this Question
Share on Google+
4 Replies


MMcCarthy
Expert Mod 10K+
P: 14,534
Try this ...

Expand|Select|Wrap|Line Numbers
  1. Dim i As Integer
  2. i = 1
  3. While i < 6
  4.     Select Case "Field" & i
  5.         Case "Title"
  6.             strFld(i) = "([Title] & ': ' & [Subtitle])"
  7.         Case "Author"
  8.             strFld(i) = "([AUTHOR] & ', ' & [SUBAUTHOR])"
  9.         Case "Subject"
  10.             strFld(i) = "Subject"
  11.         Case "Publisher"
  12.             strFld(i) = "Publisher"
  13.         Case "Year of Publication"
  14.             strFld(i) = "Year"
  15.         Case "Call No"
  16.             strFld(i) = "([DDC_NO] & ' ' & [Auth_MARK])"
  17.         Case "Acc No"
  18.             strFld(i) = "ACCNO"
  19.     End Select
  20.     i = i + 1
  21. Wend
  22.  
  23.  
Sep 12 '07 #2

P: 10
Dear
Thanks for response.
"Select Case "Field" & i" is treated as:
Select "Field1", "Field2".

But i want to use it as variable, not constant. Field1, Field2... are the names of combo boxes on the form.
Values of these combo boxes may differ in all cases

Ata

Try this ...

Expand|Select|Wrap|Line Numbers
  1. Dim i As Integer
  2. i = 1
  3. While i < 6
  4.     Select Case "Field" & i
  5.         Case "Title"
  6.             strFld(i) = "([Title] & ': ' & [Subtitle])"
  7.         Case "Author"
  8.             strFld(i) = "([AUTHOR] & ', ' & [SUBAUTHOR])"
  9.         Case "Subject"
  10.             strFld(i) = "Subject"
  11.         Case "Publisher"
  12.             strFld(i) = "Publisher"
  13.         Case "Year of Publication"
  14.             strFld(i) = "Year"
  15.         Case "Call No"
  16.             strFld(i) = "([DDC_NO] & ' ' & [Auth_MARK])"
  17.         Case "Acc No"
  18.             strFld(i) = "ACCNO"
  19.     End Select
  20.     i = i + 1
  21. Wend
  22.  
  23.  
Sep 14 '07 #3

MMcCarthy
Expert Mod 10K+
P: 14,534
Dear
Thanks for response.
"Select Case "Field" & i" is treated as:
Select "Field1", "Field2".

But i want to use it as variable, not constant. Field1, Field2... are the names of combo boxes on the form.
Values of these combo boxes may differ in all cases

Ata
Ata

I'm totally confused.

Can you explain logically (not with code) exactly what you are trying to do.
Sep 14 '07 #4

P: 10
Dear mmccarthy

Thanks for response. Sorry I could not make clear question. But the problem has been solved as under with a slight change:
I hope you may easily understand the following code:

Expand|Select|Wrap|Line Numbers
  1. Dim i As Integer
  2. Dim cb(5) As ComboBox
  3. Set cb(1) = Field1
  4. Set cb(2) = Field2
  5. Set cb(3) = Field3
  6. Set cb(4) = Field4
  7. Set cb(5) = Field5
  8.  
  9. i = 1
  10. While i < 6
  11.     Select Case cb(i)
  12.         Case "Title"
  13.             strFld(i) = "([Title] & ': ' & [Subtitle])"
  14.         Case "Author"
  15.             strFld(i) = "([AUTHOR] & ', ' & [SUBAUTHOR])"
  16.         Case "Subject"
  17.             strFld(i) = "Subject"
  18.         Case "Publisher"
  19.             strFld(i) = "Publisher"
  20.         Case "Year of Publication"
  21.             strFld(i) = "Year"
  22.         Case "Call No"
  23.             strFld(i) = "([DDC_NO] & ' ' & [Auth_MARK])"
  24.         Case "Acc No"
  25.             strFld(i) = "ACCNO"
  26.     End Select
  27.     i = i + 1
  28. Wend
  29.  
  30.  
Ata

I'm totally confused.

Can you explain logically (not with code) exactly what you are trying to do.
Sep 17 '07 #5

Post your reply

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