Results 1 to 4 of 4

Thread: can i use select case in vba?

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2004
    Posts
    33

    can i use select case in vba?

    hi all~
    i am currently doing a report using access97. i am quite new to vba so i am not sure if i am able to do this anot.

    this is the situation:

    I got a table with abbreviations. Eg. A = Apple, O = Orange. But I only keyed in A and O in my table. However in my report, i want my txtbox to display Apple instead of A when it was looped out into the txtbox.

    my question is:

    can i write a select case to generate out the words? if it is possible, how to use the code builder cause i notice the coding is a little different from the way i code using vb.

    Thanks in advance~~
    cheers,
    stupidz

  2. #2
    Junior Member Shattered's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    26
    short answer : yes

    code builder does a lot of things differently but you can code the select case statement the same way you do in vb.
    "much to learn you still have"

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2004
    Posts
    33
    Hi Shattered,

    thanks for the fast reply!!!
    hmm..
    if it is in vb this is the way to code:

    VB Code:
    1. Select Case txtAbb.text
    2.       Case "A" : txtFullName.text = "Apple"
    3.       Case "O" : txtFullName.text = "Orange"
    4.       End Select

    but i tried in vba, i.e i open up the code builder and try to code in it, the txtbox control does not has the .TEXT attribute and i was coding in the Detail_Format(Cancel As Integer, FormatCount As Integer) event.

    did i code in the correct event? and how do i pass in a value into a textbox?

    Thanks again~~
    cheers,
    stupidz

  4. #4
    Junior Member Shattered's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    26
    hmm...

    Your code does actually work - just tried it myself. The code needs to be in the Change event though

    VB Code:
    1. Private Sub txtAbb_Change()
    2. Select Case txtAbb.Text
    3.       Case "A": txtFullName.Text = "Apple"
    4.       Case "O": txtFullName.Text = "Orange"
    5. End Select
    6. End Sub

    The text boxes do have a text property IF you are using vba objects, they don't if your using form objects.

    If you got your text box from the FORMS toolbar then it won't have the text property.

    If you got your text box from the CONTROL BOX toolbar then it will have the text property.
    "much to learn you still have"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width