Lookup values in a table

jeo

Registered User.
Local time
Today, 18:11
Joined
Dec 26, 2002
Messages
299
I have a form where user picks start/end dates for a certain person for a certain task.
What I want to do is to check and see if that person is already doing something on a particular day. I’m storing all the start/end dates in a table where I have employee ID as a foreign key.
Is there a way I can lookup already allocated date value for certain employee ID in that one table?
Thanks.
 
Hi

Hi jeo. I have a good example of this. I have had to strip the DB down to post it on the forum.

Basically - Hold the shift key when you open the DB. Open the Orders Form.
Input 2 new orders. Select an Employee (theres only 1). Make sure the second order matches the first. Hey presto.....if they are the same date and time an error is generated.

Hope this help!!
Phil.
 

Attachments

This was very, very helpful!
Thank you for going out of your way and posting this. I really appreciate it!
Now I need to figure out what you are doing.
Thank you again.
 
What does this statement do in a query?
<>[Forms]![frmOrders]![OrderId]
I'm not sure what <> stands for.
Thanks.
 
Yep

Cheers Pat, beat me to it.....
 
why are you using that code line? <>[Forms]![frmOrders]![OrderId]
what purpose does it serve?
 
What does that do....

Back again. I had LOTS of help with this one (thanks to Dan Cat).
This should explain everything:

Everything starts within the before update of the service time field.
First we declare two variables tmeAddService and tmeMinusService.
These two variables are Date. Why? because time comes under the date
variable. If you notice when you create a date field in tables - the
data type always says date/time. Because they share the same variable.

Ok, well I want these two variables to equal servicetime minus 90
minutes and servicetime plus 90 minutes.

Thus we use the DateAdd function. A bit confusing because we're not
playing with dates here, but as I said time also shares the date
variable. So we are going to take 90 minutes away from service time.
Thus:

DateAdd (the function to add to a date/time value) "n" (what time
interval we want to use n = minutes, m = months) - "-90" (this is the
figure we are going to add so to subtract we need to detail a negative
figure) - "Me.ServiceTime" (The value that we are going to perform the
calculation on).

Thus tmeMinusService = DateAdd("n", -90, Me.ServiceTime) means

tmeMinusService = Me.Servicetime - 90 minutes.

Ok that’s the first part - now we need to ascertain whether to warn the
user or prevent the user from adding the order.

In anser to your question:(in Dans words!!).

I created a new query called qryOrderChk. I usually put
chk on the end of names when I am using that object for validation.
The query is a basic select query. The criteria prevents the current
record from being displayed (<>[Forms]![frmOrders]![OrderId]) and also
only displays records that have the same service date as the current
record ([Forms]![frmOrders]![ConfirmedServiceDate]).
Now back to the
code.

So first up I wanted to check whether any records match the current
record with the same service date and time. I do this with the following
line:

If DCount("OrderId", "qryOrderChk", "ServiceTime =
Forms!frmOrders!ServiceTime") > 0 Then

So all I am doing here is saying how many (DCount) records (OrderId)
within (qryOrderChk) which have a (serviceTime) equal to the current
record (Forms!frmOrders!ServiceTime). If that figure is more than 0 (>0)
then run the next piece of code:

DoCmd.OpenForm "frmOrderChk", acNormal, , "[ServiceTime] =
Forms!frmOrders!ServiceTime"

You know this bit - open the form frmOrderChk (which has a record source of qryOrderChk) and limit the records displayed to where the ServiceTime is the same as the service time of the current record on the form.

Forms!frmOrderChk!labDuplicate.Visible = True

This part makes visible the message telling the user they cannot make
the order.

Cancel = True prevents the record from being updated
Exit Sub quits the sub routine so no further code is executed.
This part is now done.

Second up we want to check that if there are no matching records then
check to see if there are any records within the 90 minute range.

Here I did exactly the same thing:

DCount("OrderId", "qryOrderChk", "ServiceTime >=#" & tmeMinusService &
"# And ServiceTime <= #" & tmeAddService & "#") > 0 Then

How many OrderIds are there in qryOrderChk which have a service time
equal to or greater than tmeMinusService (we have already made
tmeMinusService = the current servicetime - 90 minutes) but also has a
servicetime equal to or less than tmeAddService(90 minutes more than the current service time) If there is more than 0 then execute the following code:

DoCmd.OpenForm "frmOrderChk", acNormal, , "[ServiceTime] >= #" &
tmeMinusService & "# And [ServiceTime] <= #" & tmeAddService & "#"

Open the form frmOrderChk and only display the records that have a
service time of greater than or equal to tmeMinusService and that have a servicetime of less than or equal to tmeAddService.

Syntax: The syntax is a little more complicated on the second bit of
code.

Declared variables cannot be enclosed in " " marks thus you need to use
& to identify them and & again to unidentify them. You also need to
surround these variables with a # but these must be contained within the
" " marks.

Hope that helps,
Phil.
 
Last edited:
Thanks, this helped a lot.
Now I need to figure out how to replace your +-90 minutes with 2 sets of dates. I have a start, end date variables and requestedstart,requestedend date variables.
 
I have been struggling with this and I’m wondering if you could possible give me a head start on what I need to do. I created a little database to replicate what I need done.
I’m not sure if I need to create a query to check for the date conditions or if I need to create “BeforeUpdate” event and code date conditions in there.
I just don’t know which way to go and honestly, I tried both and neither method worked for me, so I’m lost :(
Any help would be greatly appreciated! Thank you.
 

Attachments

All Done

Joe please refer to the attached database.
I feel I have done what you have asked for.
Change the start date for order 2 to 01/01/2005 and see..........
:D
Phil.
 

Attachments

Thank you so very much for doing this, Phil! I really appreciate it. My manager has been on me all day for this.
I do have a couple of questions.
1. With what I see, I don't really need a request start/request end dates.
2. It seems like this is not based on the StaffID, just StaffName because StaffID for bob is 1 and 2. Does that matter at all? I really need to work for a specific StaffID.
Or am I not following something?
Thanks again. If you are ever in South Bend, IN, I will take you out!
 
Hello Again

Yes I did wonder when I looked at your DB.
I would have had seperate tables for staff and Activity for starters.

tblStaff
StaffID PK
FName
LName

tblActivity
ActivityID PK
StaffID FK
Activity
ActivityStart
ActivityEnd

Relationship is between StaffID

I would have then created a query, and then a form from the query.

I however am no expert on Normalization!!!

I am sure others will have a better way of doing things!

Have a play + search the forum, its all trial and error!!
Good Luck,
Phil.

PS: If I get time at work tomorrow I will create a sample DB for you.
 
Thanks.
At this point in time I really don't care about the activity stuff.
I had to shrink my current db down so i just created this one and didn't pay attention to what i put in the table.
You're right, activity should be in the separate table.
So putting aside activity stuff, I'm thinking this will not work if for that same person I choose a range of dates that is not = to the already scheduled dates.
Let's say I have 01/01/05 - 01/10/05 already scheduled and then i come in and try to add something for 01/07/05 - 01/20/05.
Would that work? That's why I thought I needed all those < and > calculations.
Thank you again for all your help! Reeeeeeeaaaaaaly appreciate it!
 
StaffID

Hello again.
Let's say I have 01/01/05 - 01/10/05 already scheduled and then i come in and try to add something for 01/07/05 - 01/20/05.
Would that work?

Answer: Try it and see!!

Also
Currently your staffID does not actually do what you want. If I understand it correctly you would like each member of staff to have a unique identifier i.e.

StaffID 1 = Bob Smith
StaffID 2 = Joe Smith
StaffID 3 = Alan Jones

As it stands at the moment, (using the above example) you could get:

StaffID 1 = Bob Smith
StaffID 2 = Joe Smith
StaffID 3 = Alan Jones
StaffID 4 = Bob Smith
StaffID 5 = Alan Jones
StaffID 6 = Alan Jones

So the staffID does not identify a member of staff. That is why I suggest seperate tables.

I will post an example at the first opportunity.
Phil.
 
I tried this and it didn't work :(
"Let's say I have 01/01/05 - 01/10/05 already scheduled and then i come in and try to add something for 01/07/05 - 01/20/05.
Would that work?"
I'm hoping that because of the StaffID situation - it's not working correctly.
And yes, each member should have a unique identifier.
Thank you again for your help!
 
Hello Again

Hi Joe. (Woops) I mean Jeo....See attached DB. I have not done it all for you but I hope you will be able to modify what I have done to suit your requirements.

Basically I have created seperate tables as discussed. I then created a few queries + forms.

You select the member of staff from the drop down as you do the Activity.

If you input the same start date for a user then an error is generated. You must then amend the date in order to continue. This however does not work as you want it as you need to verify both dates. I will let you work that one out!!

Good Luck,
Phil.
 

Attachments

Thank you for all your help!
I will try and figure out how to make this work from here...
Again, thanks for all your time and efforts!
 
When i added some msgboxes to see if the values are correct, it seems like the activitystartdate is being picked up from the form both times.
I don't think it's picking up values from the query.
Am i wrong? Clikc to cmd button to see msgboxes (both dates are the same)
 

Attachments

Users who are viewing this thread

Back
Top Bottom