高分求解.两个问题???
Option Explicit
Private Sub cmdjie_Click()
Dim rs_settlement As New ADODB.Recordset
Dim rs_settlement1 As New ADODB.Recordset
Dim rs_settlement2 As New ADODB.Recordset
Dim sql As String
Dim sql1 As String
Dim sql2 As String
Dim time As Data
Dim time1 As Data
Dim var As String '用来记录category表里的车辆类型
Dim var1 As Long '用来记录两个时间的差值。以分钟来记录
Dim var2 As Long '用来记录所用的小时数
Dim var3 As Long '用来记录所用的天数
Dim var4 As Long '用来记录车辆类型的数字
Dim var5 As Long '用来记录车辆的单价
Dim var6 As Long '用来记录车辆总价
Dim var7 As Long '用来保存天数时的金额
If txtcar.Text = " " Then
MsgBox "车牌号不能为空 ", vbOKOnly + vbExclamation, " "
txtcar.Text = " "
Exit Sub
End If
sql = "select cl_number,cph,sj,in_time,out_time,flag,money,in_yg_id,out_yg_id,info.cl_type_xh,type_name from information as info,category as cate where info.cl_type_xh=cate.cl_type_xh and cph= ' " & Trim(txtcar.Text) & " ' And flag = 0 "
If rs_settlement.State = adStateOpen Then rs_settlement.Close
rs_settlement.Open sql, conn, adOpenKeyset, adLockOptimistic
If rs_settlement.RecordCount > 0 Then
var = rs_settlement!type_name & " "
rs_settlement!out_time = Now()
rs_settlement!out_yg_id = usermi
time = rs_settlement!out_time & " "
time1 = rs_settlement!in_time & " "
var1 = DateDiff( "m ", time, time1)
End If
sql1 = "select cl_number,cph,sj,in_time,out_time,flag,money,in_yg_id,out_yg_id,info.zf_number,cl_type_xh,time_state1,time_state2,dj from information as info,fees as cate where info.cl_type_xh=cate.cl_type_xh and cph= ' " & Trim(txtcar.Text) & " ' And flag = 0 "
If rs_settlement1.State = adStateOpen Then rs_settlement1.Close
rs_settlement1.Open sql, conn, adOpenKeyset, adLockOptimistic
If rs_settlement1.RecordCount > 0 Then
var2 = var1 / 60 '取小时
var3 = var2 / 24 '取天数
var3 = Fix(var3)
var4 = rs_settlement!cl_type_xh
If var4 Then
Select Case var4
Case 1
var7 = var3 * 20
Case 2
var7 = var3 * 30
Case 3
var7 = var3 * 40
Case 4
var7 = var3 * 20
Case 5
var7 = var3 * 30
End Select
End If
End If
var2 = Fix(var2)
sql2 = "select * from fees where time_state1= <var2 and time_state2> var2 "
If rs_settlement2.State = adStateOpen Then rs_settlement2.Close
rs_settlement2.Open sql, conn, adOpenKeyset, adLockReadOnly
If rs_settlement2.RecordCount > 0 Then
var5 = rs_settlement2!dj & " "
var6 = var7 + var1 * var4
End If
txttime.Text = Val(var3) & "天 " & Val(var2) & "小时 "
txtjie.Text = Val(var6)
txttype.Text = Val(var)
rs_settlement.Close
rs_settlement1.Close
rs_settlement2.Close
End Sub
1.可以像这样付值吗??rs_settlement!out_time = Now()
rs_settlement!out_yg_id = usermi
2.为什么最后的txttime,txtjie,txttype显示出来都是没有结果的呀.找了半天不知道原因呀.
[解决办法]
If rs_settlement.State = adStateOpen Then rs_settlement.Close
rs_settlement.Open sql, conn, adOpenKeyset, adLockOptimistic
If rs_settlement.RecordCount > 0 Then
var = rs_settlement!type_name & " "
rs_settlement!out_time = Now()
rs_settlement!out_yg_id = usermi
time = rs_settlement!out_time & " "
time1 = rs_settlement!in_time & " "
var1 = DateDiff( "m ", time, time1)
End If
这是什么啊,你是想实现现存入数据库在调出把
If rs_settlement.State = adStateOpen Then rs_settlement.Close
rs_settlement.Open sql, conn, adOpenKeyset, adLockOptimistic
If rs_settlement.RecordCount > 0 Then
var = rs_settlement!type_name & " "
rs_settlement!out_time = Now()
rs_settlement!out_yg_id = usermi
rs_settlement.update
'然后看一下数据库,赋值成功了吗?
time = rs_settlement!out_time & " "
time1 = rs_settlement!in_time & " "
var1 = DateDiff( "m ", time, time1)
End If
[解决办法]
If rs_settlement.State = adStateOpen Then rs_settlement.Close
rs_settlement.Open sql, conn, adOpenKeyset, adLockOptimistic
If rs_settlement.RecordCount > 0 Then
var = rs_settlement!type_name & " "
rs_settlement!out_time = Now()
rs_settlement!out_yg_id = usermi
rs_settlement.update
'然后看一下数据库,赋值成功了吗?
time = rs_settlement!out_time & " "
time1 = rs_settlement!in_time & " "
var1 = DateDiff( "m ", time, time1)
'这样看看相关变量的值,是不是你要的:
debug.print time & "/ " & time1 & "/ " & var1
End If