Excel 在access中自动填写表单中的ID
我想在access中为DB创建一个ID,该ID由date.time.user ID自动生成,如/161212.2227.s978904/ 我在VBA excel中创建它,但不在access中工作Excel 在access中自动填写表单中的ID,excel,vba,ms-access,Excel,Vba,Ms Access,我想在access中为DB创建一个ID,该ID由date.time.user ID自动生成,如/161212.2227.s978904/ 我在VBA excel中创建它,但不在access中工作 Sub IDgen() Dim ID, Yr, Dt, Mth, Hr, Min As Integer ID = Environ("username") Yr = Right(Year(Date), 2) Mth = Format(Month(Date), "#00") Dt = Format(D
Sub IDgen()
Dim ID, Yr, Dt, Mth, Hr, Min As Integer
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")
Sheets("Sheet1").Range("A2").Value = "C" & Yr & Mth & Dt & "." & Hr & Min & "." & ID
End Sub
使用一个函数返回ID,并从表单中调用该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
谢谢大家!
我是这样做的
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