自动填写访问表单中的ID

时间:2016-12-12 20:39:44

标签: excel vba access

我想在访问数据库的表单中创建一个ID,其中ID由date.time.user ID自动生成,如/ 161212.2227.s978904 /

我在VBA excel中创建它但不在访问中工作。

MapView

2 个答案:

答案 0 :(得分:1)

您使用一个返回ID的函数并从表单中调用:

Function GetId() As String
    Dim ID As String, Yr As String
    Dim Dt As String, Mth As String
    Dim Hr As String, Min As String

    ID = Environ("username")
    Yr = Right(Year(Date), 2)
    Mth = Format(Month(Date), "#00")
    Dt = Format(Day(Date), "#00")
    Hr = Format(Hour(Time), "#00")
    Min = Format(Minute(Time), "#00")

    GetId = "C" & Yr & Mth & Dt & "." & Hr & Min & "." & ID

End Function

答案 1 :(得分:0)

谢谢!

我是这样做的。

Private Sub Form_Load()

Yr = Right(Year(Date), 2)
Mth = Format(Month(Date), "#00")
Dt = Format(Day(Date), "#00")
Hr = Format(Hour(Time), "#00")
Min = Format(Minute(Time), "#00")

Me.Text56.Value = "C" & Yr & Mth & Dt & "." & Hr & Min & "." & Environ("username")

End Sub