我是想在FORM1 LOAD时在FORM1 里的一个TEXT1里显示当前月份的最大号,如下代码错哪?
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim sq1 As String
cnn.Open "provider=Microsoft.jet.OLEDB.4.0;data source= " & App.Path & "\分录表.mdb"
sq1 = "Select max(号) as hao from flb where 月='" & Month(DTPicker1) & "'"
rst.Open sq1, cnn, adOpenKeyset, adLockOptimistic
rst.MoveLast
gethao = Format(Val(hao.Value) + 1)
rst.Close
Set rst = Nothing
TEXT1.TXT=gethao
错误:数据类型不正确,以下句子出错
rst.Open sq1, cnn, adOpenKeyset, adLockOptimistic
如何得到这个号呀?求大家看看
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim sq1 As String
cnn.Open "provider=Microsoft.jet.OLEDB.4.0;data source= " & App.Path & "\分录表.mdb"
sq1 = "Select max(号) as hao from flb where 月='" & Month(DTPicker1) & "'"
rst.Open sq1, cnn, adOpenKeyset, adLockOptimistic
rst.MoveLast
gethao = Format(Val(hao.Value) + 1)
rst.Close
Set rst = Nothing
TEXT1.TXT=gethao
错误:数据类型不正确,以下句子出错
rst.Open sq1, cnn, adOpenKeyset, adLockOptimistic
如何得到这个号呀?求大家看看
sq1 = "Select max(号) as hao from flb where 月 = " & Month(DTPicker1)就可以了
Dim rst As New ADODB.Recordset
Dim sq1 As String
cnn.Open "provider=Microsoft.jet.OLEDB.4.0;data source= " & App.Path & "\分录表.mdb"
sq1 = "Select max(号) as hao from flb where 月=" & Month(DTPicker1)
rst.Open sq1, cnn, adOpenKeyset, adLockOptimistic
'rst.MoveLast
gethao = Format(Val(rst!hao) + 1)
rst.Close
Set rst = Nothing
TEXT1.TXT = gethao
gethao = rst!hao + 1
else
gethao = 1
end if
rst.open "SELECT MAX(a)+1 AS NEWFIELD FROM A",cnn,adOpenStatic
rst.filed(0)即为你想要的
因为用了MAX,所以查出来的是最大值,所以查出来的记录集只有一条,也就不必用movefirst or movelast
rst.filed(0)应改为rst.fileds(0)