MS Access DSUM issue - ms-access

I have a text box in a form that sums up an "encumbered" column with the where condition matches the ID number in that table and the ID shown in the form. I get a #Name error but all of the naming is correct.
=DSum("EncAmount",[tblEncumbrances],"[BID]='" & [frmProcurementEdit]![BudgetItemID] & "''")
tblEncumbrances is the table name, EncAmount is the column whose sum I need to add up. FrmProcurementEdit is the form that the textbox is on and BudgetItemID (Also on the form) needs to match BID(In tblEncumbrances)
Am I missing something here? Any help would be greatly appreciated!!

The literal table name must be enclosed in quote marks. Also, there is an extra closing apostrophe delimiter.
According to your comment, linking fields are not same data type. This will definitely be an issue and really should correct data structure. However, it can be dealt with. Assuming BID is an integer number:
=DSum("EncAmount", "[tblEncumbrances]", "[BID]=" & CInt([BudgetItemID]))
or
=DSum("EncAmount", "[tblEncumbrances]", "[BID]=" & Val([BudgetItemID]))

=DSum("[EncAmount]","tblEncumbrances","[BID]='" & [BudgetItemID] & "'")

Related

Expression in Textbox not passing value to the table

Obviously I am not an Access expert or I would not be asking this question. I created a small database with several tables. On a form, there are several combo boxes for the user to choose different combinations of medium, paper, sizes, etc. I have already created an expression that returns the correct value I need, but I cannot figure out how to get this value into the correct field on the table to store with the record the form is creating. Below are screen shots of the form and a couple of the tables. I have also included the expression I am using. I need the value that the expression returns to go into tbl1Artwork and populate the ArtWorkSKU field.
Expression:
=Left([PieceName],4) & [cbxArtist].Column & [cbxMedium].Column & [cbxPaperType].Column & [cbxPrintType].Column & [cbxSize].Column
The ArtWorkSKU text box is unbound as I had to type the expression in there. I am not sure if this is the correct way to accomplish the goal. In the tables below, except for the PK, all fields are Short Text.
All guidance is greatly appreciated.
Saving calculated data is usually not necessary and can be risky. Saved value can become 'out of sync' with raw data. Value can be calculated when needed.
Saving calculated data requires code (macro or VBA).
Can be as simple as Me!fieldname = Me.controlname.
Real trick is figuring out what event(s) to put code into. In your case, most likely form BeforeUpdate.
Advise not to use spaces nor punctuation/special characters (underscore only exception) in naming convention. Better would be ArtworkSKU or ArtworkSKUnum or Artwork_SKU_Num.
Create the following function in VBA:
Function UpdateSKU()
Me.ArtWorkSKU = Left(Me.[PieceName],4) & Me.[cbxArtist].Column(3) & _
Me.[cbxMedium].Column(2) & Me.[cbxPaperType].Column(2) & _
Me.[cbxPrintType].Column(2) & Me.[cbxSize].Column(2)
End Function
Then, on the form, update the After Update event property (not vba) of each "feeder" control to:
After Update: =UpdateSKU()

DSUM - Data Typed Mismatched in Criteria Expression

Withdrawal: DSum("[quantity]","Withdrawal","[part_number]= '&[part_number]&'")
I am getting the above error due to the statement above.
I have an Orders table, would like to collate and display the withdrawals quantity for each part number. Data type is number, am I missing anything here?
Your help is much appreciated.
You're working with 2 types of quotes, and doing it improperly. The proper code should be:
Withdrawal: DSum("[quantity]","Withdrawal","[part_number]= " & [part_number])
In the code above, the second [part_number] was still inside a string so not filling properly. As a result you were comparing part numbers with the string [part_number]
Missing a quote after the first apostrophe and before the second.
Withdrawal: DSum("[quantity]","Withdrawal","[part_number]= '" & [part_number] & "'")
part_number is a text field? If not, remove the apostrophes.

MS Access - Dlookup criteria from selected item (listbox)

I've seen similar questions but the provided answers couldn't solve my problem.
In access I created a form.
From a listbox you can select a name. The names are listed in the table tNames in the column names_combined (last name, given name) . In two other columns last name and given name are separated.
On the right side of the listbox you can find information about the name which will be shown in text boxes.
The goal is to show the last name from table tNames.lastname by looking for tNames.names_combined.
So I tried this:
=Dlookup("lastname";"tNames";"names_compined =" & Me.listbox)
However I just get error messages in my text box.
Thanks in advance!
DLookup requires commas not colons.
This should work assuming all the names of tables/fileds and controls are correct:
=Dlookup("lastname","tNames","names_compined='" & Me.listbox & "'")
Also make sure the actual bound field of your listbox is the combined name (by the way you code says comPined).
Finally as it was pointed out in the other answer me.something will only work in the form itself or its VBA module. Everywhere else you need a global identifier.
Try with:
=Dlookup("lastname";"tNames";"names_combined = '" & Forms!YourForm!listbox & "'")

DSUM won't let me give it criteria

I have a few tables: Order, OrderLine, and Cost being relevant here.
In my Order entry form, I have two subforms, one for OrderLine and one for Cost. At the footer, I have a "subtotal" which I simply want to sum up my extended prices on my orderline sub form. I tried doing something like this:
=Sum([OrderLine subform].[Form]![PriceExtended])
But it gives me an #Error (without ever telling me the error anywhere, that's another annoying problem...) Well, okay that's not a problem we can just go straight to the database with it. So I tried using DSUM like so
=DSum("PriceExtended","OrderLine","OrderUnique=" & [OrderUnique])
And that gave me an error and it just made the box blink... well okay it's not picking up the OrderUnique field, so we'll try hardcoding it
=DSum("PriceExtended","OrderLine","OrderUnique=SHOP1234")
Nope, still giving me the stupid blinking... okay then, let's try no criteria
=DSum("PriceExtended","OrderLine")
And that works just fine, except of course it sums up every order ever and I only want to sum up the lines for this particular order.
So why would my DSum criteria not accept "OrderUnique=SHOP1234"?
Since OrderUnique is defined as a Text field, you need to surround the value with single quotes or double quotes. You want the criteria string to look like:
OrderUnique='SHOP1234'
, so you would hard code that as
=DSum("PriceExtended","OrderLine","OrderUnique='SHOP1234'")
or build it with
=DSum("PriceExtended","OrderLine","OrderUnique='" & [OrderUnique] & "'")

How to Get the Column/Field Name Using Access VBA

I've copied the recordsource of a subform to a recordset by RecordClone. this subform source is composed by a query (some tables) and all the fields of this query were renamed like, for instance, id_document to "ID Document", date to "Document Date". what I need is to get those new names instead of the original names. instead of id_document, I want to get "ID Document". I tried to get them in the property or fiels collection, unsuccessfully. if any of you know how to do that, please, help me. I'd appreciate your help.
thanks in advance.
P.S.: this is the way I renamed the field in the query design view:
"ID Document": id_document
Take a look at this excellent answer from Gord Thompson (whose name is familiar to many here):
How to export a table in access to CSV with dot in field names through VBA?
It's not exactly what you're doing (this person wanted to remove a "." from field names) but you're doing something pretty similar. You can probably do a DLookup from a crosswalk table to figure out what the column should be named.
Just build a new table called tblCrosswalk and then fill it like this:
Old New
id_document ID Document
date Document Date
etc... etc...
Then, in the build the CSV header line section, instead of those "Replace" functions, put this:
s = DLookup("New", "tblCrosswalk", "Old = '" & fld.Name & "'")