Private Sub Command4_Click()
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("型体编号表")
rs.AddNew
rs("型体编号") = Me.型体编号
rs.Update
rs.Close
Set rs = Nothing
Me.型体编号 = Null
Me.型体编号 = uf_AutoNum("型体编号表", "型体编号")
End Sub
Private Sub Form_Load()
Me.型体编号.Enabled = True
Me.型体编号 = uf_AutoNum("型体编号表", "型体编号")
Me.型体编号.Enabled = False
Me.文本1.SetFocus
End Sub
'使用方法:Me.型体编号 = uf_AutoNum("型体编号表", "型体编号")
Function uf_AutoNum(strTable As String, strfldName As String)
'strtable 表名
'strfldname 字段名
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset(strTable)
Dim strYY As String
Dim strMaxNum As String
Dim strMidYY As String
Dim strMidNum As String
strYY = Format(Date, "YY")
Debug.Print rst.RecordCount
If rst.RecordCount > 0 Then
strMaxNum = DMax(strfldName, strTable)
Debug.Print strMaxNum
strMidYY = Mid(strMaxNum, 3, 2)
strMidNum = Format(Val(Right(strMaxNum, 3)) + 1, "000")
If strMidYY = strYY Then
uf_AutoNum = "GL" & strYY & strMidNum
Else
uf_AutoNum = "GL" & strYY & "001"
End If
Else
uf_AutoNum = "GL" & strYY & "001"
End If
rst.Close
Set rst = Nothing
End Function