变量cl和sj由窗体上的文本框得到。初次在access中写vba,我不知道在sql查询中如何将字段名用变量表示。系统提示:运行时错误,语法错误,操作符丢失。
请前辈指点,谢谢。
代码如下:
Private Sub 还车时间_AfterUpdate()
Dim sj As String
Dim cl As String
cl = Me.车类.Value
Select Case Me.使用时间.Value
Case Is <= 2
sj = "2小时价格"
Case 2.1 To 4
sj = "4小时价格"
Case 4.1 To 23.9
sj = "8小时价格"
Case 24 To 719.9
sj = "24小时价格"
Case Else
sj = "30天价格"
End Select
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("select " & sj & " from 价格 where 车类 ='" & cl & "'")
rs!sj = Me.使用费用.Value
rs.Close
Set db = Nothing
End Sub
[此贴子已经被作者于2006-8-1 12:15:33编辑过]
|