Results 1 to 5 of 5

Thread: [RESOLVED] MS Access 2010 Select case problem

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2013
    Posts
    20

    Resolved [RESOLVED] MS Access 2010 Select case problem

    Hi,

    I'm trying to use select case to calculate payment due date for credit cards, but each time it only uses the first case whatever the selection is, any help.

    Code is

    Code:
    Private Sub credit_payment_AfterUpdate()
    
    Dim duedate, duedate1, duedate2, duedate3 As Date
    Dim payment_val As String
    
    payment_val = credit_payment.Value       'combobox selected value
    
    Select Case due_date
    Case payment_val = "Credit1"
    duedate = DateSerial(year(credit_pay_date.Value), month(credit_pay_date.Value) + IIf(day(credit_pay_date.Value) < 20, 0, 1) + 1, 15)    'credit_pay_date textbox with the purchase date
    credit_due_date.Value = duedate    'due date textbox
    Case payment_val = "Credit2"
    duedate1 = DateSerial(year(credit_pay_date.Value), month(credit_pay_date.Value) + IIf(day(credit_pay_date.Value) < 27, 0, 1) + 1, 22)
    credit_due_date.Value = duedate1
    Case payment_val = "Credit3"
    duedate2 = DateSerial(year(credit_pay_date.Value), month(credit_pay_date.Value) + IIf(day(credit_pay_date.Value) < 1, 0, 1) + 1, 27)
    credit_due_date.Value = duedate2
    Case payment_val = "Credit4"
    duedate3 = DateSerial(year(credit_pay_date.Value), month(credit_pay_date.Value) + IIf(day(credit_pay_date.Value) < 13, 0, 1) + 1, 13)
    credit_due_date.Value = duedate3
    End Select
    End Sub

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: MS Access 2010 Select case problem

    Your Select Case statement doesn't make sense. A Select Case is supposed to specify an expression to test the value of and then a number of values to match it against. You're specifying 'due_date' as the expression to test but it looks like the actual expression you want to test is 'payment_val'. Think about it; a Select Case is used in place of multiple If...ElseIf statements. If you converted your code to use If...ElseIf then would it make sense?
    Code:
    If due_date = (payment_val = "Credit1") Then
    I think it's clear that that is nonsense. Presumably what you would actually want is this:
    Code:
    If payment_val = "Credit1" Then
    so it's 'payment_val' that you should be selecting cases for:
    Code:
    Select Case payment_val
        Case "Credit1"
            '...
        Case "Credit2"
            '...
        Case "Credit3"
            '...
        Case "Credit4"
            '...
    End Select

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2013
    Posts
    20

    Re: MS Access 2010 Select case problem

    Thank you for the reply. What you are saying does make sense, I'll test it and see how it works.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: MS Access 2010 Select case problem

    Quote Originally Posted by nightheart2010 View Post
    What you are saying does make sense
    That's a given.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jan 2013
    Posts
    20

    Resolved Re: MS Access 2010 Select case problem

    It is working perfectly. Thank you again

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