Need help on Dmax please! Critical
I have the following scenario
Table: testWLog.
WLngNo field: has W001,W002, W003, W004 and W005
WStrNm field: has W001, W002, W003, W004 and W005
PreparedBy field: Default =environ("Username") has UserA (for rows W001 to W003). It Also has UserB (for rows W004 and W005).
Everytime I run my code I get W004 for UserA. At this time I should now get W006 for UserA because W005 and W006 has been taken by UserB.
Here is the following Module, Function, On-click Events
Please look at it.
Module:
Option Compare Database
Public MyDmax As Long
Public Function testDmax()
MyDmax = Nz(DMax("[WLngNo]", "testWLog", "Preparedby='" & Environ("Username") & "'"), 0) + 1
End Function
*********************
On my Form:
Option Compare Database
Dim WNext As Long
Dim ULocalWS As String ' for later use
Private Sub Command0_Click()
Call testDmax()
WNext = MyDmax
txtIAssignWS.SetFocus
txtIAssignWS.Text = "W" & Format(CStr(WNext), "000")
UmyDmaxWS = txtIAssignWS.Text
End Sub
***********************
The Value of MyDmax for UserA is 4. It should be 6 because UserB used 4 and 5 already.
Please help me. Thanks
I have the following scenario
Table: testWLog.
WLngNo field: has W001,W002, W003, W004 and W005
WStrNm field: has W001, W002, W003, W004 and W005
PreparedBy field: Default =environ("Username") has UserA (for rows W001 to W003). It Also has UserB (for rows W004 and W005).
Everytime I run my code I get W004 for UserA. At this time I should now get W006 for UserA because W005 and W006 has been taken by UserB.
Here is the following Module, Function, On-click Events
Please look at it.
Module:
Option Compare Database
Public MyDmax As Long
Public Function testDmax()
MyDmax = Nz(DMax("[WLngNo]", "testWLog", "Preparedby='" & Environ("Username") & "'"), 0) + 1
End Function
*********************
On my Form:
Option Compare Database
Dim WNext As Long
Dim ULocalWS As String ' for later use
Private Sub Command0_Click()
Call testDmax()
WNext = MyDmax
txtIAssignWS.SetFocus
txtIAssignWS.Text = "W" & Format(CStr(WNext), "000")
UmyDmaxWS = txtIAssignWS.Text
End Sub
***********************
The Value of MyDmax for UserA is 4. It should be 6 because UserB used 4 and 5 already.
Please help me. Thanks