Your responses are not very helpful. Forget the Access and queries etc.
What is the database about?
What exactly would be put on label? Give us a sample of what you want the label to look like.
Is this a hospital or cafeteria setup or similar?
Is there only 1 menu per meal?
You've got to have more than 2 tables (in my view).
Here's a sample of a description of a business.
From RogersAccessLibrary
Narrative ZYX Laboratories requires an employee tracking database. They want to track information about employees, the employee's job history, and their certifications. Employee information includes first name, middle initial, last name, social security number, address, city, state, zip, home phone, cell phone, email address. Job history would include job title, job description, pay grade, pay range, salary, and date of promotion. For certifications, they want certification type and date achieved.
An employee can have multiple jobs over time, (ie, Analyst, Sr. Analyst, QA Administrator). Employees can also earn certifications necessary for their job.
Can you work from it and tell us about your database/business in plain English?
I think we have our wires crossed, the labels are not the problem and the database design/relationship is not the problem.
Regardless if the database is for a hospital, cafeteria setup or 1 menu per meal or 2 menu per meals or 1 table, 2 tables 1000 tables...
This information is total irrelevant and does not focus on the main problem.
The problem is the code is not working correctly, if a date already exists within the table regardless of the kitchen name, the code will not run the second part of the else statement
i.e. to re-order the meals again.
When the other kitchens print their labels, the labels are blank this is because the query that provides this information to the reports have the following criteria;
·Current date ·Name of the kitchen
As the code has not run the second part of the else statement there is no current dates within the table, this is why the labels are blank.
Sorry Brucey, but to me I'd like to know WHAT the purpose of the database is and to see a poster developed data model to see the tables and relationships. It helps clarify the situation, entities involved and gives some idea of the poster's Access/database skills.
This information is total irrelevant and does not focus on the main problem.
Perhaps not, but it helps readers put the problem/opportunity into context.
The problem is the code is not working correctly, if a date already exists within the table regardless of the kitchen name, the code will not run the second part of the else statement
I'm sure that's what you are seeing and feeling, but for readers - we're asking "What code?"
Show us - code; the desired label with sample data; and a jpg of your tables and relationships; and/or a copy of your database with no private info and just enough data to highlight the problem.
You're going to have to give readers something to work with if we are to help you.
I have then added two new Clients that have their diets prepared in separate kitchens.
Testing outcome
Print labels for kitchen 1 with today’s date – works ok
Print labels for kitchen 2 with today’s date – works ok
Print labels for kitchen 1 with tomorrows date – works ok
Print labels for kitchen 2 with tomorrows date – no ( labels are blank)
But if I delete kitchen 1 tomorrow date from the diet table and then print kitchen 2 with tomorrow date it works ok,
Surely this must be because the code is not action the And clause?
I’m think the code looks at the query QryPrintDataVBA , this query pulls
·(SELECT MAX(MealDate) from TblDietPlan) ·kitchen name
I think the code sees the date has been entered is already in the database and does not action the AND clause for the kitchen name therefore does not re-order the diets.
Code
If (DCount("*", "QryPrintDataVBA", "[MealDate] = " & Format(txtCusDate, "\#mm\/dd\/yyyy\#") & _
" AND [Kitchen] = '" & Me.ComboKitchenName & "'") <> 0) Then
'A date provided exists in the table
DoCmd.SetWarnings False
stDocName = "McrPrint_Customise_Labels"
DoCmd.RunMacro stDocName
I don't use macros, so can not help there.
What happened to Kitchens.
As suspected, your data model is not helping.
What exactly are you trying to do? I've looked at some of your posts since September. Many people have offered advice. You seem to have moved from Restaurants and Kitchens to Hospitals and Snacks.
People can not answer you with focused comments/advice when you have a moving, and poorly defined requirement.
Start with a clear statement of requirements. Build some test data and scenarios.
Working from your statement of requirements build a model. Test the model with your sample scenarios and data. Adjust as necessary until your model satisfies your test scenarios. Then start building the database -- tables and relations.
Good luck with your project. It sounds interesting.
I strongly advice against the use of macro's they are restrictive and anything they can do VBA can do better. Now you are deviding work between VBA and Macro's which makes things worse
In your Macro McrReOrderDietCusDate, you are first creating a temp table, creating temp tables for the sake of creating a report is bad bad bad practice
Next you are updating the temp table, again not the best thing
In your query is hardcoded hospital = "Ailsa Hospital", which is not good since my hospital is "Hospital 1", worse yet, you have a tekst field in your tblpatient to store this... Instead of having a Primary key in your tblHospitals and a Foreign key in your tblPatient. I am sure there is a host of other things I could comment on...
To your immediate problem....
Testing outcome
Print labels for kitchen 1 with today’s date – works ok
Print labels for kitchen 2 with today’s date – works ok
Print labels for kitchen 1 with tomorrows date – works ok
Print labels for kitchen 2 with tomorrows date – no ( labels are blank)
But if I delete kitchen 1 tomorrow date from the diet table and then print kitchen 2 with tomorrow date it works ok,
This is INDEED due to your (SELECT MAX(MealDate) from TblDietPlan) in the criteria of your qryPrintDataVBA since it will force the query to only select the latest date PERIOD, no dependancy on hospital or kitchen at all
On top of this your query doesnt have a Kitchen field, how would you expect the DCount to work on kitchen?
Code:
If (DCount("*", "QryPrintDataVBA", "[MealDate] = " & Format(txtCusDate, "\#mm\/dd\/yyyy\#") & _
" AND [Kitchen] = '" & Me.ComboKitchenName & "'") <> 0) Then
Worse yet, I dont even see a Kitchen field in any of the tables? so what are we
Did you inherit this database or did you start this project from scratch?
If this is something (relatively) new, I am sorry but the best way forward indeed may be to do a full redesign with lessons learned from this one.
Starting with a proper definition of your needs and a proper normalization process from that definition.