我需要帮助;我创建了一个基于以下标准存储保费的表:
Table_Policy_Premium
1. Category: A
2. Min Age: 0
3. Max Age: 20
4. Premium: USD1000
同一类别可能具有其他年龄范围,最小值21最大值64,以及下一个字段中的溢价。
我有另一张表employee_data,
,其中有一个高级字段;我希望根据针对每个员工的以下标准从TPP表更新。
如果Table_Policy_Premium
- Category
与Category
中的employee_data
匹配,且employee_data
中的年龄介于0到20之间,请更新以下字段来自Employee_Table
的{{1}}具有适当的溢价。
答案 0 :(得分:0)
只需在您将在查询(或表单)中调用的模块中创建公共函数,该函数将返回给定类别和年龄的溢价值。
Public Function getPremium(strCat As String, intAge as Integer) As Double
'variables
Dim strQuery As String
Dim rstQuery As dao.Recordset
Dim dbs As dao.Database
'set database
Set dbs = CurrentDb
'prepare query
strQuery = "SELECT Premium " & _
"FROM Table_Policy_Premium " & _
"WHERE Category = '" & strCat & "' AND " & _
"[Min Age] <= " & intAge & " AND " & _
"[Max Age] >= " & intAge & ";"
'open recordset
Set rstQuery = dbs.OpenRecordset(strQuery)
'check if there is a record
If rstQuery.EOF Then
'no record - set premium to 0
getPremium = 0
Else
'record found
getPremium = rstQuery!Premium
End If
Set rstQuery = Nothing
Set dbs = Nothing
End Function
只需在查询中将此字段作为字段插入即可调用函数:getPremium([category],[age])