Dlookups with two or more criteria in Access 2007 - ms-access-2007

I've searched around for a solution to this but am probably not asking the question correctly. I'm fairly new to Access but I need someone's help.
On my "CSEIrrelevants" form I have a couple of Dlookups to autupopulate after updating a previous field entry. They are CustomerName and AgreementName. Essentially, when someone enters a value into the CustomerID and AgreementID fields the subsequent two fields return values from CustomerDatabase Table from CustomerName and AgreementName columns.
The CustomerID Dlookup is working fine asthe references are unique but my problem arises when dealing with the Agreement IDs as these are not unique. Agreement number 1 (the most common agreement number) is returned every time a "1" is entered in the AgreementID field.
What I want is for my Dlookup to return the first instance in the AgreementName column on the CustomerDatabase Table when the CustomerID is A12345, for example.
Thanks in advance for any help on this one guys, much appreciated.
Sean

Related

Querying via a form with value from textbox as criteria

The situation: metadata about biological specimens are collected in an Access table. The specimens come from human patients and patient data are collected in a separate table. To limit the amount of private health information we have hanging around, the patient database must be updated with new patients only when we actually receive samples from them.
So that the data entry workers know when they need to update the patient table, I want a button in the specimen data entry form that will pass an entered patient id value as criteria to a query.
The query looks like this right now:
SELECT Patients.[Patient id]
FROM Patients
WHERE (((Patients.[Patient id])=[Forms]![Specimen entry]![patient id]));
but it never has results, even when I run it from records that I know correspond to patients in the patient table. How do I fix this?
Suggestions about what to call this situation so that I can make better searches about it would also be appreciated. I'm an Access novice.
The query looks correct, but make sure the WHERE clause is comparing numbers to numbers or strings to strings (not a number to a string). Also confirm that the form and textbox names are correct. A quick test using your query worked for me.
Depending on how you plan to present the information, you can also dynamically create the query in VBA and then pass the information to the form.
For searching, I'd recommend some combination of access, dynamic, query, and vba.
alternative option
If you're only looking to see if a single patient exists in the table, it may be simpler to use the dlookup function:
If IsNull(DLookup("[Patient ID]", "Patients", "[Patient ID]='" & Me.Patient_ID & "'")) Then MsgBox "does not exist"
This will check to see if the patient exists (return a number) or does not exist (returns NULL).
https://support.office.com/en-us/article/DLookup-Function-8896cb03-e31f-45d1-86db-bed10dca5937

MS Access manual Auto incrementing field

Im building a system for my company to keep track of internal orders, inbetween our warehouses, we have material that goes out warehouse 1 to warehouse 2 and we kind of lose track of how much of "x" is in warehouse 1 and how much in warehouse 2, so i want to implement this access db where a user fills a form and says: order 1: 500 of "x" order 2: 300 of "y". then another user fills an exit form where he says 1 of "x" going out, so i would need the program to keep track of total order and how much as gone out to fill order 1 and so on...
My idea here is to have both an order number and an id number for each of "x" everytime someoneone assembles 1 "x" they fill the form and print a label directly from the access (i have this part working already) while keeping a record of when it was assembled, who verified and what was verified (it will work as a quality control also).
What i dont know is how to program the db so when it reaches 500 of "x", the id number for "x" starts again from 1
This is the one major issue with my program right now, i'm not experienced in access db's or vba, but im getting there with a tip and a trick from here and there, so, no need to be careful with the technical language, i will google it if i have to :p
EDIT:
The table structure goes as follows:
1 table as the main table where I record the check that is made for every product, where I include the model of the product, the said ID that I want to reset after a number of products checked, and a concatenated field that includes most of this information to generate a qr code.
Then there is a table for the Order Number, which is connected to a form to record each new order with a date/time field, the order number itself and the number of products. This number of products must then be called from the code that will count how many products have been checked to date and keep the order number field updated so we can keep track of the order.
Then there is another minor table just to get values for the form, the product models
Thank you for your answers ;)
See this MSDN Documentation
Unfortunately in Access, you cannot 'reset' an ID field, unless you move the records to a newly created table and use that table for every 500 records.
As for the user control and login form, I'm afraid those are separate questions that must be asked in a different thread.
To get you started:
You can set the RecordSource of a form to a table, and when users make entries, the data will be saved to the table. You can also use a form with controls (text boxes, comboboxes, etc.) and create a button that runs a query to insert these records into a table.
The login piece - you can encrypt the database with a password. That may/may not be sufficient.
I would suggest you change your schema, if possible. Something like the following:
Orders
OrderID (Autonumber)
ProductID (link to your Products table)
QuantityRequested
Deliverables
DeliverableID (Autonumber)
OrderID (link to your Orders table)
SequenceNumber: in the BeforeInsert event set this value equal to:
DCount("*", "Deliverables", "OrderID=" & Me.OrderID) + 1
I'm assuming that your form has a control named OrderID that is bound to the OrderID field of the Deliverables table.
The code uses the DCount() function to get the count of all the other deliverables that have already been created for this order. If this is the first deliverable, DCount() will return 0. It then adds 1 to this count to get the sequence number of the next deliverable.
If the new SequenceNumber is greater than the quantity requested, you could display a message saying that the order has been filled and cancel the creation of the Deliverable record.
This is just one approach and it is not a complete solution. I'm assuming that once assigned a sequence number a deliverable cannot be deleted. You might need to make allowances for deliverables that get lost or damaged. You could incorporate a status field to the Deliverable table to deal with this, but you would still need to make a decision about what to do with the SequenceNumber.

MS Access & Queries

Looking for a bit of help for an Access/Query question pertaining to a homework assignment that has 6 separate questions. I have completed all but one. The assignment wants me to do the following query.
The name, unit price, and quantity ordered for all products purchased by a customer whose id is entered from the keyboard.
Is there a function I'm overlooking for the ID entity criteria? I've looked and searched but cannot find how to add that part into the query. Thanks in advance for any help.
You can accomplish this by making the ID criteria a parameter. Access will then pop up an input form that lets you enter the value of the parameter.
You can read more here and here.

MS Access- Table normalization and query design problems

I have a tricky thing I'm trying to get working
I have a table that contains events, and 10 fields populated with ID Numbers of employees who attended, and a comment box for each one. I tried to create a query that uses a combo-box with the ID Number to Search for the events they attended, and display them in a form cleanly (IE without displaying other peoples, or having a large number of text boxes everywhere). I got it partially working but I could not figure out how to go any farther. I can't figure out how to separate out the fields by the people. I was toying with the idea of having the event listed say 10 times with one person per record but that would cause alota bloat.
Any ideas how to do this? Different formats/other approaches would be great as well.
Thanks guys.
I would split the tables... have one that contains the event, with an eventID field as an AutoNumber. Then have another table called Attendance with three fields: eventID containing the ID of the event, employeeID, and Comment for the comment. This would then even allow you to create another table containing more info about the employee like first name and last name for use in reports.

SQL query in Access

Basically, I've been trying to make this query work for a while in Access and it's really frustrating me so instead of playing around with the criteria, I've decided to just do it in SQL instead but I can't quite figure out how to do this bit.
What I need to do is create a query that shows which members haven't returned an item that they're currently taking out on loan. If possible I'd like to include a calculated field to state the date is was due back and how many days late it is.
The fields I'm using are as follows;
Table = Loan
Toy Name
Hire Date
Duration (in days)
Returned Date (if it hasn't been returned, the cell is blank)
Table = Toy
Purchase Price
Hire Price
you wrote:
a query that shows which members haven't returned an item
your table does not have members in it. secondly table toy have nothing related to toy like toy name or something. Please provide further detail of tables.
one more question what is the meaning of blank? Is it Null or blank string?