ClearwaterDiver
Registered User.
- Local time
- Today, 16:53
- Joined
- Aug 6, 2017
- Messages
- 17
I have read as many of the posts on this and similar subjects and still having an issue. Heck, maybe I shouldn't even be using DLookup. After all, I just want to give the 'x and y' of an array and return the result!
background -
I have a table in my database that is a temperature correction chart that I am legally bound to use, no formula is approved. The data is literally from a scanned PDF from 1913... (google: ttb table 1 ) The table is 100 fields wide (1-100 degrees F) with 206 or so rows that correlate from 1 to 206 alcohol proof (indicated)
The field header names ARE numbers, but I cannot see changing them. I see where @The_Doc_Man said he had not seen all-numeric fields in 25 years, I might just have a candidate!
The key column is the 1-206 numbers that correlate to observed proof. (there is a section of data intentionally missing from the for below 31 degrees and 76 proof. Likely this is because ice would form and gauging would be inaccurate)
WHAT I HAVE:
I have a Table and a Form for a 'proofing operation' where I type in temperature and proof to one decimal point, I have a working simple operation that reads calibration correction factor for the hydrometer and thermometer based on me selecting the serial number of the instrument form a drop-down combo box and it fills both the serial# and correction factor fields based on a simple VB script for 'AfterUpdate' on the serial number field. This took me a few hours to get working but this site helped my out immensely!
The next step after getting the corrected values is to do temperature compensation via my large table "tempCorrection". This table is only whole degrees and whole proof, so double interpolation is needed, which takes four lookups. I am using DLookup(), and as a side note, I have this working fine an an excel spreadsheet with just Lookup() and Indirect(), but want to roll it into my database.
If I put a variable in for the 'expr' in DLookup( expr, domain [, criteria] ), it works as long as that variable is statically defined.
This version works since I have the 'expr' variables Temp and Temp1 statically defined at 40 and 41 degrees, respectively, so this only works for 40.0 to 40.99 degrees, which is obviously not much of a help. (FYI, the variables for 'domain' and 'criteria' work):
WHAT I AM STUCK WITH:
I need to have Temp and Temp1 be taken from the Form as variables (val to make it a value if it is not, Fix is to round down, and str to make it back to a string to hand to DLookup() as the expr field
Temp = Str(Fix(Val(Me.[Actual Temp])))
I spent about 8 hours now researching and trying different things.
Thinks I have tried:
attachments are the form and the table with a portion of the data
background -
I have a table in my database that is a temperature correction chart that I am legally bound to use, no formula is approved. The data is literally from a scanned PDF from 1913... (google: ttb table 1 ) The table is 100 fields wide (1-100 degrees F) with 206 or so rows that correlate from 1 to 206 alcohol proof (indicated)
The field header names ARE numbers, but I cannot see changing them. I see where @The_Doc_Man said he had not seen all-numeric fields in 25 years, I might just have a candidate!
The key column is the 1-206 numbers that correlate to observed proof. (there is a section of data intentionally missing from the for below 31 degrees and 76 proof. Likely this is because ice would form and gauging would be inaccurate)
WHAT I HAVE:
I have a Table and a Form for a 'proofing operation' where I type in temperature and proof to one decimal point, I have a working simple operation that reads calibration correction factor for the hydrometer and thermometer based on me selecting the serial number of the instrument form a drop-down combo box and it fills both the serial# and correction factor fields based on a simple VB script for 'AfterUpdate' on the serial number field. This took me a few hours to get working but this site helped my out immensely!
The next step after getting the corrected values is to do temperature compensation via my large table "tempCorrection". This table is only whole degrees and whole proof, so double interpolation is needed, which takes four lookups. I am using DLookup(), and as a side note, I have this working fine an an excel spreadsheet with just Lookup() and Indirect(), but want to roll it into my database.
If I put a variable in for the 'expr' in DLookup( expr, domain [, criteria] ), it works as long as that variable is statically defined.
This version works since I have the 'expr' variables Temp and Temp1 statically defined at 40 and 41 degrees, respectively, so this only works for 40.0 to 40.99 degrees, which is obviously not much of a help. (FYI, the variables for 'domain' and 'criteria' work):
Code:
Private Sub Hydrometer_Serial__AfterUpdate()
Me.[Hydrometer Correction] = Me.[Hydrometer serial#].Column(1)
Dim strTable As String
Dim Proof As String
Dim Proof1 As String
Dim cProof As Double
Dim cProof1 As Double
Dim Temp As Variant
Dim Temp1 As Variant
Dim cTemp As Double
Dim cTemp1 As Double
strTable = "tempCorrection"
Proof = "key = " + Str(Fix(Val([Actual Proof])))
Proof1 = "key = " + Str(Fix(Val([Actual Proof] + 1)))
Temp = "[40]"
Temp1 = "[41]"
cProof = DLookup(Temp, strTable, Proof)
cProof1 = DLookup(Temp, strTable, Proof1)
cTemp = DLookup(Temp, strTable, Proof)
cTemp1 = DLookup(Temp1, strTable, Proof)
Me.[Interpolated Proof] = cProof + (Me.[Actual Proof] - Fix(Val([Actual Proof]))) * (cProof1 - cProof) + ((Me.[Actual Temp] - Fix(Val([Actual Temp]))) * (cTemp1 - cTemp))
End Sub
WHAT I AM STUCK WITH:
I need to have Temp and Temp1 be taken from the Form as variables (val to make it a value if it is not, Fix is to round down, and str to make it back to a string to hand to DLookup() as the expr field
Temp = Str(Fix(Val(Me.[Actual Temp])))
I spent about 8 hours now researching and trying different things.
Thinks I have tried:
Code:
DOES NOT WORK:
Temp = """ & Chr(91) & Str(Fix(Val(Me.[Actual Temp]))) & Chr(93) & """
DOES NOT WORK:
Temp = Chr(34) & Chr(91) & Str(Fix(Val(Me.[Actual Temp]))) & Chr(93) & Chr(34)
DOES NOT WORK (takes value, not field name)
Temp = Str(Fix(Val(Me.[Actual Temp])))
DOES NOT WORK (error message 39)
Temp = Chr(91) & Str(Fix(Val(Me.[Actual Temp]))) & Chr(93)
DOES NOT WORK (runtime error 2471 error message 39)
Temp = "[" + Str(Fix(Val(Me.[Actual Temp]))) + "]"
ERROR
Temp = '[' & Str(Fix(Val(Me.[Actual Temp]))) & ']'
DOES NOT WORK (runtime error 2471 error message 39)
Temp = "[" & Str(Fix(Val(Me.[Actual Temp]))) & "]"
DOES NOT WORK (runtime error 2471 error message 39)
Temp = "[" + Str(Fix(Val(Me.[Actual Temp]))) + "]"
DOES NOT WORK (runtime error 2465 cant find |1 )
Temp = [Str(Fix(Val(Me.[Actual Temp])))]
unexpected end of statement
Temp = ""[Str(Fix(Val(Me.[Actual Temp])))]""
DOES NOT WORK (runtime error 'temp'
Temp = Str(Fix(Val(Me.[Actual Temp])))
cProof = DLookup("[Temp]", strTable, Proof)
RETURNS INCORRECT VALUE ) looks up 40, not field 40
Temp = Str(Fix(Val(Me.[Actual Temp])))
cProof = DLookup([Temp], strTable, Proof)
ERROR 39
Temp = Str(Fix(Val(Me.[Actual Temp])))
cProof = DLookup("['" & Temp & "']", strTable, Proof)
says there is an extra (
cProof = DLookup("[Str(Fix(Val(Me.[Actual Temp])))]", strTable, Proof)
attachments are the form and the table with a portion of the data