Access: Code for adding a date is not working

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,342
Office Version
  1. 365
Platform
  1. Windows
I have a combo box on a form. When the user changes selection I want a date to populate another field on the same form as the combo box. this code is not working. Nothing happens when I change the combo selection

Code:
Private Sub Combo4_Change()

If TextQuoteExpDate01 = "All Quotes" Then
TextQuoteExpDate01 = "*"
Else

If TextQuoteExpDate01 = "Only Valid Quote" Then
TextQuoteExpDate01 = Now()
Else

If TextQuoteExpDate01 = "Current and Expired within 30 Days" Then
TextQuoteExpDate01 = Now() - 29
Else

If TextQuoteExpDate01 = "Current and Expired within 60 Days" Then
TextQuoteExpDate01 = Now() - 59
Else

If TextQuoteExpDate01 = "Current and Expired within 90 Days" Then
TextQuoteExpDate01 = Now() - 89
Else

If TextQuoteExpDate01 = "Current and Expired within 180 Days" Then
TextQuoteExpDate01 = Now() - 179
Else

If TextQuoteExpDate01 = "Current and Expired within 360 Days" Then
TextQuoteExpDate01 = Now() - 359
Else


End If
End If
End If
End If
End If
End If
End If

End Sub

Help. Please!
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Code:
Option Compare Database

Private Sub Combo4_Change()

If ComboQuoteValidity01 = "All Quotes" Then
TextQuoteExpDate01 = "*"
Else

If ComboQuoteValidity01 = "Only Valid Quote" Then
TextQuoteExpDate01 = Now() - 1
Else

If ComboQuoteValidity01 = "Current and Expired within 30 Days" Then
TextQuoteExpDate01 = Now() - 29
Else

If ComboQuoteValidity01 = "Current and Expired within 60 Days" Then
TextQuoteExpDate01 = Now() - 59
Else

If ComboQuoteValidity01 = "Current and Expired within 90 Days" Then
TextQuoteExpDate01 = Now() - 89
Else

If ComboQuoteValidity01 = "Current and Expired within 180 Days" Then
TextQuoteExpDate01 = Now() - 179
Else

If ComboQuoteValidity01 = "Current and Expired within 360 Days" Then
TextQuoteExpDate01 = Now() - 359
Else


End If
End If
End If
End If
End If
End If
End If

End Sub

But still not working. uhg!
 
Upvote 0
A few things:
- When checking one field for so many different values, use a Case statement instead of a bunch of IFs - much cleaner, and easier to read (see: https://www.techonthenet.com/access/functions/advanced/case.php).
- Note that "Now()" returns current date AND time. "Date" will return just the current date.
- When referencing fields on the Form, preface all of them with "Me.".

See if this works for you:
Code:
Option Compare Database

Private Sub Combo4_Change()

    Select Case Me.ComboQuoteValidity01
        Case "All Quotes"
            Me.TextQuoteExpDate01 = "*"
        Case "Only Valid Quote"
            Me.TextQuoteExpDate01 = Date - 1
        Case "Current and Expired within 30 Days"
            Me.TextQuoteExpDate01 = Date - 29
        Case "Current and Expired within 60 Days"
            Me.TextQuoteExpDate01 = Date - 59
        Case "Current and Expired within 90 Days"
            Me.TextQuoteExpDate01 = Date - 89
        Case "Current and Expired within 180 Days"
            Me.TextQuoteExpDate01 = Date - 179
        Case "Current and Expired within 360 Days"
            Me.TextQuoteExpDate01 = Date - 359
        Case Else
            '
    End Select

End Sub
 
Last edited:
Upvote 0
You are welcome.
 
Upvote 0

Forum statistics

Threads
1,215,756
Messages
6,126,692
Members
449,330
Latest member
ThatGuyCap

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top