Sumif with And Vlookup in Access VBA

mahmed1

Well-known Member
Joined
Mar 28, 2009
Messages
2,302
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi Guys

what is the equivalent of doing a sumif or theses formula in Access VBA

TotalHoursColumn =Sumifs([TotalHours],[Date],@[Date])
TotalRecColumn =@[TotalHours]/@[Received]
FteCol = @[AHT]/Vlookup(@[Area],TableAreaLookup,3,0)
Im trying to avoid doing it in excel and build it in to the access table using Vba
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Build a query and use the group by built in functionality. Lose the spreadsheet thought process and adopt the database thought process. They are not the same.
 
Upvote 0
Hi
This is new to me and was hoping someone could help with a VBA approach
 
Upvote 0
 
Upvote 0
Hi
This is new to me and was hoping someone could help with a VBA approach

To conditionally sum a field in VBA, the most straightforward approach is to use DSum().


For writing the SQL-esque criteria, reference alansidman's link. If there is still anything that you can't work out, post back and we'll go from there.

:)
 
Upvote 0
Thankyou

i have tried this

TotalReceived = DSum("[ContactsReceived]","[tblContacts]","[MyId]='" & [id_] & "'" And "[Date_]<=#" & [Date_] & "#")

I get no results using this
 
Upvote 0
This "'" before the word And leaves And outside of quotes. That will never work. Also, these make no sense
- [Date]<=#" & [Date_] & "#" You have a field named [Date] (not good)? If so, you are saying "Where date field value is less than or equal to date field value". It can only be equal to itself, never less.
- You have [Date] in your original post and [Date_] in that expression. Only one of them can be correct?
- are you trying to say "Where today's date ( written as Date() ) is less than or equal to the value in a field named [Date] (or [Date_] ) ?
 
Upvote 0
TotalReceived = DSum("[ContactsReceived]","[tblContacts]","[MyId]='" & [id_] & "'" And "[Date_]<=#" & [Date_] & "#")

I get no results using this

A lot depends on where you are putting this.

As Micron pointed out, it's not really clear what your variables ([id_] and [Date_]) are intended to refer to. So it will help to troubleshoot to know where this code is going and where the variables are coming from.

Also, your criteria expression should be written like the WHERE clause of a SQL statement (see this post). Here, using the forum's formatting tools can actually be very helpful; when you wrap your DSum() statement in VBA tags, the problem Micron mentions of the AND being outside (rather than inside) the criteria statement becomes rather clear - it is blue but should be orange.

VBA Code:
TotalReceived = DSum("[ContactsReceived]","[tblContacts]","[MyId]='" & [id_] & "'" And "[Date_]<=#" & [Date_] & "#")

vs...

VBA Code:
TotalReceived = DSum("[ContactsReceived]","[tblContacts]","[MyId]='" & [id_] & "' And [Date_]<=#" & [Date_] & "#")
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,520
Members
449,088
Latest member
RandomExceller01

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