Submit Button query

gmazza76

Well-known Member
Joined
Mar 19, 2011
Messages
628
Office Version
  1. 365
Platform
  1. Windows
Good morning,

I think this is a simple one, but it is a bit early for me this morning.

I am trying to add a userform to an Access database table which I have, but how do I add a if query to give me an outcome to add in in.
I need to be able to submit an answer based on if the dates are higher/lower as per below.

Code:
.Fields("Worked By") = Worksheets("Calcs").Range("B7").Value
.Fields ("When Keyed") = (DTPicker1 = DTPicker2,"Same Day Booking",if(DTPicker1 < DTPicker2,"In Advance","After Booking")

All help appreciated
thanks
 

Some videos you may like

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
L

Legacy 456155

Guest
Here are at least 3 ways. The first is easier to read IMO.

VBA Code:
With .Fields("When Keyed")
    If DTPicker1 = DTPicker2 Then
        .Value = "Same Day Booking"
    ElseIf DTPicker1 < DTPicker2 Then
        .Value = "In Advance"
    Else
        .Value = "After Booking"
    End If
End With

.Fields("When Keyed") = Choose(DTPicker1 = DTPicker2, "Same Day Booking", DTPicker1 < DTPicker2, "In Advance", True, "After Booking")
    
.Fields("When Keyed") = IIf(DTPicker1 = DTPicker2, "Same Day Booking", IIf(DTPicker1 < DTPicker2, "In Advance", "After Booking"))
 

Watch MrExcel Video

Forum statistics

Threads
1,122,518
Messages
5,596,630
Members
414,082
Latest member
sasmita

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
Top