Results 1 to 10 of 10
  1. #1
    Join Date
    Aug 2007
    Posts
    102

    Unanswered: Select Case error

    Hello,

    I have a listbox ,paymnt',on a form, with 2 values. Just below it there is a command button 'sendpay' that I am trying to use a Select statement (Case based on paymnt)...It's not working. Can anyone see what a newbie can't? thanks so much. Here's the code:
    Code:
    Private Sub sendpay_Click()
    Select Case Me.paymnt
      Case "Check"
        DoCmd.OpenForm "Paymntcrdtcrd"
      Case "Credit Card"
        DoCmd.OpenForm "Paymntchk"
      Case Else
    End Select
    End Sub
    I also tried this and it didn't work:
    Code:
    Private Sub sendpay_Click()
    If Me![paymnt].Value = 1 Then
     DoCmd.OpenForm "paymntcrdtcrd"
    Else
     DoCmd.OpenForm "paymntchk"
    End If
    help..any ideas
    imrosie



    [/CODE]
    Last edited by imrosie; 08-08-07 at 12:30.

  2. #2
    Join Date
    May 2003
    Location
    New York, NY
    Posts
    225
    Try using the Value Property:


    Code:
    Private Sub sendpay_Click()
    
    Select Case Me.paymnt.Value
      Case "Check"
        DoCmd.OpenForm "Payment1"
      Case "Credit Card"
        DoCmd.OpenForm "Payment2"
      Case Else
    End Select
    Last edited by Mark Gambo; 08-08-07 at 12:31.

  3. #3
    Join Date
    Aug 2007
    Posts
    102
    Hi Mark,

    Thanks for the quick reply....Does it matter that paymnt is actually a listbox?

    just curious.

  4. #4
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    You may want to learn to use the debugger. That helps a lot when learning how all these little nuances work.

    Click on the line
    Select Case Me.paymnt

    Then hit F9. That will insert a breakpoint on that line, and when ever your
    code is running it will stop on that line, and you can step through the code
    (using F8) to see what is happening, and what variables contain what values.
    Inspiration Through Fermentation

  5. #5
    Join Date
    Aug 2007
    Posts
    102

    response to F9

    yes I did use the debugger and did a "step into"'. I get ru-time error message (2447) that this:
    Code:
    Select Case Me.paymnt.Value
    is an invalid use of the . (dot) or ! operator or invalid parenthesis. There are no parentheis, so it either the . (dotJ) or it requires the !. I've tried the exclamation between Me and paymnt...it still complains.

    thanks
    imrosie

  6. #6
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Me!paymnt is the proper syntax. .Value is optional in this context.
    Access knows what you want without using .Value.

    Are you sure the control is named paymnt, and not lstPaymnt or payment...
    Inspiration Through Fermentation

  7. #7
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    What would happen if you ran
    Code:
    MsgBox Me.paymnt.Value
    MsgBox Me!paymnt
    'etc
    George
    Home | Blog

  8. #8
    Join Date
    Aug 2007
    Posts
    102
    I don't know...Will try and get back to you GeorgeV. thanks

    imrosie

  9. #9
    Join Date
    Jun 2007
    Location
    Maitland NSW,Australia
    Posts
    388
    I agree with RedNeckGeek you may have an incorrect name for your list box.

    The following code works.

    The list box is named paymnt,row source type is Value List,row source is "Cheque";"Credit Card", bound to column 1

    Private Sub sendpay_click()
    Select Case Me!paymnt
    Case "Check"
    DoCmd.OpenForm "frm_1"

    Case "Credit Card"
    DoCmd.OpenForm "frm_2"

    End Select

    Exit_sendpay_click:
    Exit Sub

    Err_sendpay_click:
    MsgBox Err.Description
    Resume Exit_sendpay_click

    End Sub

  10. #10
    Join Date
    Aug 2007
    Posts
    102
    Hi PoppaSmurf, GeorgeV and RedNeckGeek,,
    I thank you for all your help. I actually recreated the listbox, assuming that it was possibly corrupt(?!?!?)...
    Then I added back the following code and it worked:

    Code:
    Private Sub sendpay_Click()
    Select Case Me.paymnt.Value
      Case "Check"
        DoCmd.OpenForm "paymntchk"
      Case "Credit Card"
        DoCmd.OpenForm "paymentcrdtcrd"
      Case Else
        MsgBox "Please choose a payment method"
    End Select
    End Sub
    thanks again,
    imrosie
    Last edited by imrosie; 08-09-07 at 01:44.

Posting Permissions

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