我有一个表单,它会在文本框中显示voucher_id的下一个值。我能够做到这一点。问题是当我单击保存按钮时,文本框的值是相同的。我必须关闭表单并重新运行它以刷新文本框的值。点击保存按钮后,有人可以帮我显示下一个值吗?这是我的代码snipet
Private Sub Form_Load()
Dim rcset As New ADODB.Recordset
Dim conConnection As New ADODB.Connection
conConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
App.Path & "\" & "db_finance.mdb;Mode=Read|Write"
conConnection.CursorLocation = adUseClient
conConnection.Open
Set rcset = conConnection.Execute("SELECT Max(voucher_id) FROM voucher")
Text1.Text = rcset(0) + 1
End Sub
非常感谢任何帮助。
答案 0 :(得分:0)
尝试这样
Private Sub NextID()
Dim rcset As New ADODB.Recordset
Dim conConnection As New ADODB.Connection
conConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=" & _
App.Path & "\" & "db_finance.mdb;Mode=Read|Write"
conConnection.CursorLocation = adUseClient
conConnection.Open
Set rcset = conConnection.Execute("SELECT Max(voucher_id) FROM voucher")
Text1.Text = rcset(0) + 1
End Sub
Private Sub Form_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Call NextID()
End Sub
Private Sub Button_Click(Val sender As Object, ByVal e As System.EventArgs)
Handles Button1.Click
'// CAll Save Function - your function to to save
Call NextID()
End Sub