I've been using a file for a while in excel and it has worked fine, but I am now in the need to transfer the file over to Access and am unsure how to do it.
What I will have is a form with 2 spots for entry (1 space to enter employee number and one space to enter a MO number). I will then need a 3rd column that will be a unique number to determine whether there are multiple entries or not (This will not be a user defined entry, it will be automatically made). If the Employee Number is 132 and the MO Number is 453, the unique 3rd field would then say 132453 (Employee Number & MO Number).
So...When a new entry is made into the database through the form, it will look to see if that same set of 2 entries were entered before or if it is a new entry. If it is a new entry, it will give a time/date stamp to a column as a TIME IN. If it a duplicate of that record, it will then give a TIME OUT in another column.
Hopefully I didn't make this too confusing sounding and I appreciate any help that I can get. Here is a copy of the VBA I used in excel for this, but not sure how to transfer it over to work in Accesss. Maybe there's an easier way than transferring the VBA over, but I'm not sure. Thanks!
** In this VBA code for excel, column A was the unique Employee Number/MO Number. Column B was Employee Number. Column C was MO Number. And Column E and F were Time IN and Time OUT respectively. **
What I will have is a form with 2 spots for entry (1 space to enter employee number and one space to enter a MO number). I will then need a 3rd column that will be a unique number to determine whether there are multiple entries or not (This will not be a user defined entry, it will be automatically made). If the Employee Number is 132 and the MO Number is 453, the unique 3rd field would then say 132453 (Employee Number & MO Number).
So...When a new entry is made into the database through the form, it will look to see if that same set of 2 entries were entered before or if it is a new entry. If it is a new entry, it will give a time/date stamp to a column as a TIME IN. If it a duplicate of that record, it will then give a TIME OUT in another column.
Hopefully I didn't make this too confusing sounding and I appreciate any help that I can get. Here is a copy of the VBA I used in excel for this, but not sure how to transfer it over to work in Accesss. Maybe there's an easier way than transferring the VBA over, but I'm not sure. Thanks!
Code:
Option ExplicitDim rStart As Range
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B:C")) Is Nothing Then
If Target.Cells.Count = 1 Then
Application.EnableEvents = False
On Error Resume Next
Range("A" & Target.Row).Value = Range("B" & Target.Row) & Range("C" & Target.Row)
Application.EnableEvents = True
End If
End If
If Not Intersect(Target, Range("B2:B7500")) Is Nothing Then
Application.EnableEvents = False
Cells(Target.Row, "C").Select
Application.EnableEvents = True
Exit Sub
End If
If Intersect(Target, Range("C2:C7500")) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub
If Target = "" Then Exit Sub
Dim lc As Long, fr As Long, n As Long, nr As Long
With Application
.EnableEvents = False
.ScreenUpdating = False
n = Application.CountIf(Columns(1), Cells(Target.Row, 1))
If n = 1 Then
lc = Cells(Target.Row, Columns.Count).End(xlToLeft).Column
If lc = 1 Then
Cells(Target.Row, lc + 2) = Format(Now, "m/d/yyyy h:mm")
ElseIf lc > 2 Then
Cells(Target.Row, lc + 2) = Format(Now, "m/d/yyyy h:mm")
End If
Else
fr = 0
On Error Resume Next
fr = Application.Match(Cells(Target.Row, 1), Columns(1), 0)
On Error GoTo 0
If fr > 0 Then
lc = Cells(fr, Columns.Count).End(xlToLeft).Column
If lc = 1 Then
Cells(fr, lc + 2) = Format(Now, "m/d/yyyy h:mm")
ElseIf lc > 2 Then
Cells(fr, lc + 1) = Format(Now, "m/d/yyyy h:mm")
End If
Target.ClearContents
End If
End If
On Error Resume Next
Me.Range("C2", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error GoTo 0
nr = Me.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
Me.Cells(nr, 2).Select
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
** In this VBA code for excel, column A was the unique Employee Number/MO Number. Column B was Employee Number. Column C was MO Number. And Column E and F were Time IN and Time OUT respectively. **
Last edited: