This is a little complicated but I'll do my best to explain. In my db I have a table called L_AgeCorrection which has the following fields: Age, Sex, Frequency, AgeValue
This is a table used to assign an Age Correction value to hearing test results - since some degree of hearing loss naturally occurs with aging - OSHA lets us calculate that in before determining if the employee has an actual "significant" hearing loss.
Anyway...I have my main form F_Demographics with a tabbed control. One of the tabs is for audiograms. This has the current audiogram fields where we enter the date of test, type of test, and test results. This tab also has a subform nested in it to show the employee's baseline audiogram results. I need to compare the current and baseline results but AFTER I correct them for age. So here is an example of how I attempted to do this. On the tab for audiogram I used the After Update event to do a lookup and get the age correction values. I have unbound fields to put the Adjusted values and then unbound fields to later calculate the difference.
But for the lookup table here is the code I came up with... -
Private Sub AudioR6000_AfterUpdate()
-
-
'Get Values for current test from L_AgeCorrection table
-
If Me.AudioAgeL > 60 Then
-
Me.Adj2000CR = DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = '60' and [Sex]=Forms![F_Demographics]!empGender and [Frequency]=2000")
-
Me.Adj3000CR = DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = '60' and [Sex]=Forms![F_Demographics]!empGender and [Frequency]=3000")
-
Me.Adj4000CR = DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = '60' and [Sex]=Forms![F_Demographics]!empGender and [Frequency]=4000")
-
Else
-
Me.Adj2000CR = DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = AudioAgeL and [Sex]=Forms![F_Demographics]!empGender and [Frequency]=2000")
-
Me.Adj3000CR = DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = AudioAgeL and [Sex]=Forms![F_Demographics]!empGender and [Frequency]=3000")
-
Me.Adj4000CR = DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = AudioAgeL and [Sex]=Forms![F_Demographics]!empGender and [Frequency]=4000")
-
End If
-
-
'Get values for baseline test from L_AgeCorrection table
-
If Me.BRAge > 60 Then
-
Me.Adj2000BR = DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = '60' and [Sex]=Forms![F_Demographics]!empGender and [Frequency]=2000")
-
Me.Adj3000BR = DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = '60' and [Sex]=Forms![F_Demographics]!empGender and [Frequency]=3000")
-
Me.Adj4000BR = DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = '60' and [Sex]=Forms![F_Demographics]!empGender and [Frequency]=4000")
-
Else
-
Me.Adj2000BR = DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = BRAge and [Sex]=Forms![F_Demographics]!empGender and [Frequency]=2000")
-
Me.Adj3000BR = DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = BRAge and [Sex]=Forms![F_Demographics]!empGender and [Frequency]=3000")
-
Me.Adj4000BR = DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = BRAge and [Sex]=Forms![F_Demographics]!empGender and [Frequency]=4000")
-
End If
The first part is because the lookup table only goes up to age 60 so if they are over 60 the value is the same as if they were 60.
I think I'm so confused because not all the data fields are on the Audio tab - some of them are on the main form and some of them are on the subform.
Anyway...the error I'm getting is:
Run-time error '2447':
There is an invalid use of the .(dot) or ! or invalid parentheses.
The highlighted line is: If Me.BRAge > 60 Then
Can someone help me troubleshoot my code please? FYI...I had it working in my old 2003 Access db but for some reason I'm getting a hiccup here.
Thanks!
Bekah
15 3081
Replace you DLookUp with this: - DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = '60' and [Sex]='" & Forms![F_Demographics]!empGender & "' and [Frequency]=2000")
I didn't read through your entire post, I just saw this jump out at me, let me know if this fixes your DLookUp.
-AJ
Unfortunately that didn't do it...
@rleepac
Ok I noticed you have a few more places where you have issues, - DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = '60' and [Sex]=Forms![F_Demographics]!empGender...)
Replace with - DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = '60' and [Sex]='" & Forms![F_Demographics]!empGender & "' ...)
- DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = AudioAgeL and [Sex]=Forms![F_Demographics]!empGender...")
Replace with - DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = '" & AudioAgeL & "' and [Sex]='" & Forms![F_Demographics]!empGender & "' ...)
- DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = BRAge and [Sex]=Forms![F_Demographics]!empGender ...
Replace with - DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = '" & BRAge & "' and [Sex]='" & Forms![F_Demographics]!empGender & "' ...
NOTE: You need to work on using values like BRAge in VBA. I will look for the article for you and post it unless someone else beats me to it.
-AJ
Yup. I fixed all instances of it and I get the same error.
Try my post #4 now, and let me know.
-AJ
Ok. Fixed all that and still same error. I'd love to see the article if someone would post it that would be great!
Ok. Here is what I have now... - Private Sub AudioR6000_AfterUpdate()
-
-
'Get values for current test from L_AgeCorrection table
-
If Me.AudioAgeL > 60 Then
-
Me.Adj2000CR = DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = '60' and [Sex] = '" & Forms![F_Demographics]!empGender & "' and [Frequency]=2000")
-
Me.Adj3000CR = DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = '60' and [Sex] = '" & Forms![F_Demographics]!empGender & "' and [Frequency]=3000")
-
Me.Adj4000CR = DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = '60' and [Sex] = '" & Forms![F_Demographics]!empGender & "' and [Frequency]=4000")
-
Else
-
Me.Adj2000CR = DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = '" & AudioAgeL & "' and [Sex] = '" & Forms![F_Demographics]!empGender & "' and [Frequency]=2000")
-
Me.Adj3000CR = DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = '" & AudioAgeL & "' and [Sex] = '" & Forms![F_Demographics]!empGender & "' and [Frequency]=3000")
-
Me.Adj4000CR = DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = '" & AudioAgeL & "' and [Sex] = '" & Forms![F_Demographics]!empGender & "' and [Frequency]=4000")
-
End If
-
-
'Get values for baseline test from L_AgeCorrection table
-
If Me.BRAge > 60 Then
-
Me.Adj2000BR = DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = '60' and [Sex] = '" & Forms![F_Demographics]!empGender & "' and [Frequency]=2000")
-
Me.Adj3000BR = DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = '60' and [Sex] = '" & Forms![F_Demographics]!empGender & "' and [Frequency]=3000")
-
Me.Adj4000BR = DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = '60' and [Sex] = '" & Forms![F_Demographics]!empGender & "' and [Frequency]=4000")
-
Else
-
Me.Adj2000BR = DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = '" & BRAge & "' and [Sex] = '" & Forms![F_Demographics]!empGender & "' and [Frequency]=2000")
-
Me.Adj3000BR = DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = '" & BRAge & "' and [Sex] = '" & Forms![F_Demographics]!empGender & "' and [Frequency]=3000")
-
Me.Adj4000BR = DLookup("[AgeValue]", "L_AgeCorrection", "[Age] = '" & BRAge & "' and [Sex] = '" & Forms![F_Demographics]!empGender & "' and [Frequency]=4000")
-
End If
I read the link and I bookmarked it. It's a little confusing but if I read it a few dozen times I'm sure it will start to sink in... Thank you!
Ok, one question, what data type is Age? because if it is a number, you need to drop all the single quotes(') around the age operators, if it is a text, you need to add single quotes(') to - If Me.AudioAgeL > 60 Then
and
-AJ
It's a text field. I tried putting single quotes where you suggested but I got an error that said "expected an expression"
Well I have hit a wall, I would ask you to upload the DB, but I do not have access 2007, so I will post this on our expert help form if no one has picked this up here soon, to bring more attention to it. Sorry I couldn't help, I hope it is just something I am over looking but I just don't know without seeing the DB.
-AJ
Actually the AudioAgeL and BRAge are both calculated fields using the date of the test and a datediff calculation. So I guess it is a number field. I pulled the single quotes from the age operators and now I get a different error.
Now I get:
Run-time error '2450':
Microsoft Access can't find the form 'F_TestsAudioBaseline' referred to in a macro expression or Visual Basic code.
The BRAge data is pulled from the subform F_TestsAudioBaseline. Is that where my new problem is?
Maybe I should start a new thread? I'm wondering if my table set up is part of the problem.
I have a table for audiograms and a table for baseline audiograms. I can't for the life of me figure out why I did it that way. But I should probably just have one table for audiograms and a field that designates if it is a baseline or annual. I'll try messing with that a little and if I can't figure it out then I'll make a new post.
Thanks for all your help!
Bekah
Sign in to post your reply or Sign up for a free account.
Similar topics
by: deko |
last post by:
When doing a mail merge with Word, I can't seem to get the below
(abbreviated) routine to iterate strBookmark01 -- it just uses the first
name in the recordset for all 10 (or whatever) documents......
|
by: DataBard007 |
last post by:
Hello Access Gurus:
I use Win98SE and Access97.
I just built a simple Access97 application which holds all contact
information for my personal contacts, such as first name, last name,
address,...
|
by: Tony Williams |
last post by:
I have posted a number of posts in the Access newsgroups concerning my
problem with DLookup. I have had a number of the experts with helpful
suggestions but I still can't get it to work! This is...
|
by: g.ormesher |
last post by:
Hi, my primary key is a field called "ind"
'Code
Dim varUP as Varient
Dim varIND as Interger
varIND = Me.ind ' this sets varIND to the index value
|
by: Dixie |
last post by:
Hi, I am tyring to write some generic code that will send the source SQL for
a mailmerge to a Word template. I am trying to use DLookup to insert the
query name that is the record source for the...
|
by: mmorgan1240 |
last post by:
I have a form that I am trying to update. I would like to have a field
populated by another table (State_laws) based on the value of another
field on the form.
I have a field called "state". When...
|
by: chris.thompson13 |
last post by:
I am having a problem setting the criteria part of the DLookup method
correctly and am consequently getting an error message.
I have a database of staff duties, part of which is a query (qryDaily)...
|
by: Simon |
last post by:
Can any one see a problem with this code ( it does not work
Private Sub cmdEmailOrderPlaced_Click()
'On Error GoTo Error_Handler
Dim strTo As String
Dim strBody As String
Dim strSubject As...
|
by: DH22 |
last post by:
Access 03
I'm currently having an issue using Dlookup when trying to reference a query (criteria syntax)
Currently I have 1 table, which is L_Emps (which contains Employee_ID as my key...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |