How can I correct this code to be able to get a difference in weights for each client? - ms-access

I am working in MS Access. My end goal is a database report that shows the total amount lost so far for each client, based on the texts they send in daily. I've been able to extract the number from the message, but I need to be able to have a running report each day with how much they've lost since they first texted in. I tried this solution with no success: Access SQL Query: Find the most recent date entry for each employee for each training course
After that, I'v been working with the code from here: https://www.techonthenet.com/access/queries/weight.php. I've tried to write a query that brings up the Last Visit Date, but I keep getting type mismatches with this:
DMax("LogDate","NumberQ","TargetFK=" & TargetFK)
NumberQ is a query, where columns are TargetFK (Short text), FirstName (Short text), LastName (short text), LogDate (Date), Message (short text), and Weight (calculated field).
My question is, what am I doing wrong, and is there a better way to do it?

Since TargetFK is a text field, you need quotations around it:
DMax("LogDate","NumberQ","TargetFK='" & [TargetFK] & "'")

Related

Exporting Data with a Specific Date

Scenario:
I have a single table in access 2007 with few columns and several thousand records which I have imported form a CSV file via a “DoCmd” statement.
What I want:
I want to export these records but on a basis of specific field content and with another column’s date basis. i.e. I want to export the records with the “EQ” ( content of a columns field “SERIES”) and with a date which is one amongst the many dates the column have.
The “SERIES”, I have defined in “Criteria” in my query and it is working fine as the “SERIES” remains the same every day.
Issues:
The problem is with the date that changes every month and I cannot define or hard-code it in anywhere.
Query is working fine with the file where there is no date, but with a date, it is an issue.
Question:
Can we put a user define textbox, where user can define the date and that date will be taken by the query and will return the records with that defined date? In addition, “SERIES” is already defined in query so the result will be exact.
I use the following statement for exporting the data:
DoCmd.TransferText acExportDelim, "NewFnoSpec", "fnoquery",
"C:\Users\welcome\Desktop\Output.txt", True
Using the following 'WHERE' clause as a starting point to select records for one specific date:
WHERE (((Table1.SERIES)="First") AND ((Table1.MyDate)=#4/4/2014#));
You can prompt the user to enter a date by using:
WHERE (((Table1.SERIES)="First") AND ((Table1.MyDate)=[Enter Date]));
If there was some pattern or rule as to the desired date (i.e. first day of prior month, first Monday of prior month, etc.) you could structure the 'WHERE' clause to handle that without a prompt.
Thank you for your reply and an answer. Your answer is quite helpful. I have tried a little easier way and it worked for me. I put a text box named txtexpdate, on the form and in the query ( design mode ), in criteria I have put this :
Like "" & [Forms]![Futures]![txtexpdate] & ""
This is working fine at this juncture. And thank you once again for your efforts to answer my question. Hope this also will help others as an option to this problem.
Regards
Achal

Input mask in Access database

I have a field with a customer ID that should be in the format of C0000000001, where it has a letter at the start and up to 10 numbers after the letter with leading zeros between the letter and the number. I want the users to be able to put in C1 and have the table save C0000000001 or C1234 and have the table save C0000001234.
I want the restriction to be on the hard data in the table. The table should contain the full customer ID but I only want the users to have to enter the C and the number of the customer when entering/searching for customers. I am using Access 2010.
I believe that the first character will always be a C, but either way, it would only be one alpha character if it wasn't.
I understand what you are saying, but the majority of the data (thousands of records) are going to be from another system that stores them that way. Doing it this way limits my margin of error. Otherwise, exports from the other system will need to be manually changed prior to being imported into the database and vice versa.
Searching would only be on existing records that will be saved in the C0000001234 format, but I would like user to be able to omit the leading zeros when entering the search criteria.
This question, combined with your previous question here, suggest to me that you are trying very hard to have the data structure in your Access database exactly match the legacy system from which you receive bulk updates. That may not be necessary, or even desirable.
For example, instead of maintaining the CustomerId as Text(11) (as in the old system) you could store it in your Access database as
CustomerIdPrefix: Text(1), and
CustomerIdNumber: Long Integer or perhaps Decimal if the numeric part really can exceed 2,147,483,647
Your Customers table in Access could also include a calculated field named CustomerId as
[CustomerIdPrefix] & Right("0000000000" & [CustomerIdNumber], 10)
to give you a single 'C0000012345' value for display purposes.
For searching, your form could have a Text Box for the Prefix (default value: 'C') and another text box for the numeric part. The search could then use a condition like
[CustomerIdPrefix] = txtPrefix.Value AND [CustomerIdNumber] = txtNumber.Value
or, if the user wanted to create a Filter on the Form (or Datasheet View) it would probably be sufficient to just filter on the number part.
If you ever needed to feed information back to the legacy system you could just export a query that includes the [CustomerId] calculated field (and omits [CustomerIdPrefix] and [CustomerIdNumber]) and you'd be fine.
My suggestion would be to use forms with associated queries using the FORMAT function.
You do need to clarify where you want this implemented, but I'm going to assume you have a table set up and that you would like to be able to enter/search data from a form.
I'll create one form for input frmAdd. For the input form, I created a query that would run when a button on the form was pressed. Add two text boxes newID and newOther to the forms which are unbounded but which the user can use to enter data. The query will then pull that data and append it to your table in an altered format. Here's the SQL for that query:
INSERT INTO Customers ( [Customer ID], [Other Field] )
SELECT Left([Forms]![frmAdd]![newID].[value],1)
& Format(Right([Forms]![frmAdd]![newID].[value],Len([Forms]![frmAdd]![newID].[value])-1),"0000000000")
AS Expr1, Forms![frmAdd]!newOther AS Expr2
FROM Customers;
I'm not sure exactly what search functionality you're looking for, but this query would pull up the record data matching that of a frmSearch with a textbox search which would have the format C### or whatever entered in:
SELECT Left([Customers].[Customer ID],1) & Replace(LTrim(Replace(Right([Customers].[Customer ID],9),'0',' ')),' ','0')
AS Expr1, Customers.[Other Field]
FROM Customers
WHERE (((Customers.[Customer ID])=Left([Forms]![frmSearch]![search].[value],1)
& Format(Right([Forms]![frmSearch]![search].[value],Len([Forms]![frmSearch]![search].[value])-1),"0000000000")));
Applying the input mask is just a way to ensure that your data is correct. If you feel the need to use one, go to the table in Design View and click on the Data Type box for the customer ID field. Find Input Mask under Field Properties -> General and click it. Then hit go to the toolbar -> Design tab -> Builder. This will walk you through it.
Input mask is not the answer for this. Input mask forces the user to input the data in a certain manner. What you need is some VBA code to run in the AfterUpdate event on a form. There's no way within the table to force the data into this pattern allowing the input method that you've requested.
There may be a more efficient way to do this, but this does the job.
http://pineboxsolutions.com/access/customeriddemo.accdb

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] & "'")

MS-Access Web DB "type mismatch" when setting date as string?

This is specifically for MS-Access Web Databases (requires Sharepoint hosting) which has many limitations compared to their client counterparts, like no VBA, instead you get form macros and data macros to manage data.
I've run into a weird bug on one of my applications. I have a query used to check stock levels against a "minimum stock level" also saved in the table. The query is pretty intense and there are over 4,000 records now to check against. These querys normally take about 75s. So I have made a little label that gets updated every time the form is loaded showing the time and date the query was last run, and the duration in seconds it took. (so users can see how fresh the data is and decide if it needs to be run again)
Now, the weird thing is it works fine in my Access client, but when I sync my changes to the server and try it in a web browser I get a "type mismatch" error. A small table is used to store the start and end times whenever the query is run, that's how I get the timestamp data. These fields are in a "Date/Time" format, obviously. But it seems the problem here is changing the date format to a string format so it can be put in a label on the form. The Access client seems perfectly capable of doing this, while the web client stumbles and falls.
My problem is, how do I change data in a date/time format to a string format in a Web database? I can't figure out how to do this. The tools are so limited. I may have to end up answering my own question here but I'm posting this for others just in case.
To return a value from a data macro as string, you have to format the internal date/time format as a string. In Access an internal date/time value is a double number with the integer part as number of days since 1900, and the “decimal” time part is a fraction of 24 hours. Unfortunately if you simply wrap the date/time in the str$() function we had for 20+ years, then you get something JUST like if you type this into the debug window:
? cdbl(now())
41955.5478587963
The solution is to simply pull out each part. And “nice” is while in few cases a data macro will cast the data type, it does in this case and thus the STR$() command is not required.
The expression you thus can use is this:
Month([d]) & "/" & Day([d]) & " Time = " & Hour([d]) & ":" & Minute([d])
So say to pluck out the VERY LAST start time column from say a invoice table, since we don’t have a dmax(), then we simply sort the table in the order we want and pull out the first row.
Our data macro will thus look like:
Note how in above I simply typed in the SQL and SET the order on the date/time column. I want the MOST recent invoice start date and time. For those new to SQL, then I suggest you build a query in the query builder and specify a query in above lookup feature, since many are not "comfortable" typing in free hand SQL as I did above.
Now, in your browser side (UI) macro, you can use this code:
The above returns a formatted string that you can stuff into a text box, or as per above code change the caption of a label.
Unfortunately with silly problems like this, it becomes a path-of-least resistance thing.
Since my intended result was simply to get "a timedatestamp from a table to show up on a form (so users could see when a query was last run)", this became redesigning my form in Access to be a text field instead of a label. Text fields can be adjusted to accept "Time/Date" formats, so this is exactly what I did, it now pulls the timestamp data directly from the last record of the table and requires no extra formatting to appear in the web browser. I redesigned the text field to appear and function more like a label, and my desired function was achieved.
However, since my question specifically asks, "how do you change a time/date format into a string format in a Web db?", I will leave it here in case someone actually does solve it.

Mysql temporary database in codeigniter?

i have a deployment to do within 2 days time and for the last three days i have been busy trying to understand this one thing am stuck in. It probably might be very silly of me but please take me as a newbie.
I am using an opensource software php opensource pos and it is made on CI. Now the issue is that the reports in the application are different than what my client wants. I want to change that to the way they want it but i cant.
this is the code:
$this->db->select('sale_date, sum(total) as total, sum(profit) as profit');
$this->db->from('sales_items_temp');
if ($inputs['sale_type'] == 'sales')
{
$this->db->where('quantity_purchased > 0');
}
elseif ($inputs['sale_type'] == 'returns')
{
$this->db->where('quantity_purchased < 0');
}
$this->db->group_by('sale_date');
$this->db->having('sale_date BETWEEN "'. $inputs['start_date']. '" and "'. $inputs['end_date'].'"');
$this->db->order_by('sale_date');
return $this->db->get()->result_array();
every thing is working fine and as expected. Now i need to make some changes but the issue is i cannot find the temp database to see which fields it has. This database table (the temp one) is being used in all the reports functions, same database.
Can some one be so helpful and explain me the way it works, or how is that i can make a change to it!?
The scenario is that it is giving a summary of all the sales in the selected date range as total. I want a break down in terms of cash, credit, credit card, debit card etc.
I have another report which shows that, but not in date wise as in not saying how much in which day but in total of the date range. This one gives the total as in total sales in a day but not the break up of it as in what was what.
You can login here first:
https://demo.phppointofsale.com/index.php/login (id and password is saved on the page)
Then you can paste this link on the address bar and see the report.
https://demo.phppointofsale.com/index.php/reports/summary_sales/1969-12-31/2012-03-13/all/0
I need it to be a breakdown of the total and remove the tax, profit and subtotal columns and change that with the kind of payment as in cash | credit | cheque etc and then a total for that day.
PS: I am sorry for such a big writing but i am really stuck, please help me out. Thank you in advance.
The table name is sales_items_temp.
To see the actual database config (for database name, host, etc), look in either /system/application/config/database.php or /application/config/database.php depending on the version of Codeigniter.
To see about changing the query, check out http://codeigniter.com/user_guide/database/active_record.html.