Some ideas but can't get them to work
I've searched the forum and microsoft for somethings that may work. Forum definitely got close but I can't get it to work...
http://www.access-programmers.co.uk...ighlight=set value record number&pagenumber=1 ....came pretty close but I can't get the code to work for me. What cosmos75 is wanting is basically what I'm trying for. I tried to adapt the following code to my needs and got an error.
Private Sub Form_BeforeInsert(Cancel As Integer)
Me.SubTaskID = GetLastSubTaskID(Me.Parent!TaskID)
End Sub
Private Function GetLastSubTaskID(TaskID As Long) As Long
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.Open "Select Top 1 SubTaskID From tblSubTask Where [TaskID]=" & TaskID & " Order by [SubTaskID] Desc", Application.CurrentProject.Connection, adOpenStatic, adLockReadOnly
If rst.RecordCount = 0 Then
GetLastSubTaskID = 1
Else
GetLastSubTaskID = rst!SubTaskID + 1
End If
End Function
This is the how I changed it I tried to do it to an on click procedure just as a test, I would also like to know the best procedure to attach this to:
Private Sub Command125_Click(Cancel As Integer)
Me.VarianceNumber = GetLastVarianceNumber(Me.Parent!AFENumber)
End Sub
Private Function GetLastVarianceNumber(AFENumber As Long) As Long
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.Open "Select Top 1 VarianceNumber From VarianceLogInput Where [AFENumber]=" & AFENumber & " Order by [VarianceNumber] Desc", Application.CurrentProject.Connection, adOpenStatic, adLockReadOnly
If rst.RecordCount = 0 Then
GetLastVarianceNumber = 1
Else
GetLastVarianceNumber = rst!VarianceNumber + 1
End If
End Function
The error I got was this:
The expression OnClick you entered as the event property settingproduced the following error: Procedure declaration does not match description of event or precedure having the same name.
*The expression may not result in the name of a macro, the name of a user-defined function, or [Event Procedure].
*There may have been an error evaluating the function, event, or macro.
I don't have too great a knowledge of VBA but I'd appreciate any help. If you can think of a better way for this let me know.
--Something else I thought might work is setting up a field that's value is always one and then sum all the fields that have the certain AFENumber from my parent form. After I get this value I add one and then that value goes into my VarianceNumber field.
I know I could do a macro to filter the records that only contain the AFENumber that is active but I'm not sure how to send that from the form to the code. After I get that to work then I could use query to sum the values of the filtered forms. Someone help on this please. This seems like it would be easier, let me know if you have any ideas.
Thanks
Eric