andrewmrichards
Registered User.
- Local time
- Today, 16:53
- Joined
- Mar 15, 2012
- Messages
- 18
Hi All
I have a problem that's been baffling me all afternoon.
The concept is that a customer may place a recurring order, such as 5 items per month every month. In addition, some months they may require additional items
I have a form - frmOrdersMain, bound to tblOrderGroups which has a PK field called lngOrderGroupID. The information here is about the "main" order, such as the related customer and the date the order was placed.
It contains a sub form control containing a form called fsubOrderItemsContainer, bound to tblOrders, containing a PK of lngOrderID and a FK of lngRelatedOrderGroupID. This form shows the date that this part of the order is due for despatch, along with any notes etc.
This form also has a subform, called fsubOrderItemsGrouped, which shows the items being despatched as part of the particular OrderID selected in fsubOrderItemsContainer. On this form is a button called cmdNewOrderItems which allows a user to add new items to this order.
If there are existing items on this order, the code behind this button works perfectly. If not, I get the "No current record" error. However, I don't get told "Runtime error 3021: No current record", I just get a dialog box stating "No current record" and just to add to my joy a link asking "Was this information helpful?" - presumably thanks to someone at Microsoft with a sense of humour
There are several weird things about this.
1. The error occurs before the code executes. This means that even if I try adding "On error resume next" to the code, I still get the error. If I add a breakpoint to the first line of code - the line beginning Private Sub - I STILL GET THE ERROR! I click OK on the error message (the only choice) and THEN the breakpoint stops execution.
2. After I click OK on the error message, the code then works fine - the form I want (frmOrderItemDetails) pops up, allows me to assign items to the order and works perfectly.
3. If I click OK on the error message, then wen frmOrderItemDetails appears I cancel it without adding any items, when I return to this form there are, of course, still no items. But now, if I click on Add Items again, it works perfectly, with no error! But if I navigate off to a different order, then return and click Add Items again, once again I get the No Current Record error.
Someone please save my sanity!!!!
Anyone?!
Thank you so much.
Here's the code:
And in case it's relevant (I think not, but you never know), here's the code for NoteLastID:
I have a problem that's been baffling me all afternoon.
The concept is that a customer may place a recurring order, such as 5 items per month every month. In addition, some months they may require additional items
I have a form - frmOrdersMain, bound to tblOrderGroups which has a PK field called lngOrderGroupID. The information here is about the "main" order, such as the related customer and the date the order was placed.
It contains a sub form control containing a form called fsubOrderItemsContainer, bound to tblOrders, containing a PK of lngOrderID and a FK of lngRelatedOrderGroupID. This form shows the date that this part of the order is due for despatch, along with any notes etc.
This form also has a subform, called fsubOrderItemsGrouped, which shows the items being despatched as part of the particular OrderID selected in fsubOrderItemsContainer. On this form is a button called cmdNewOrderItems which allows a user to add new items to this order.
If there are existing items on this order, the code behind this button works perfectly. If not, I get the "No current record" error. However, I don't get told "Runtime error 3021: No current record", I just get a dialog box stating "No current record" and just to add to my joy a link asking "Was this information helpful?" - presumably thanks to someone at Microsoft with a sense of humour
There are several weird things about this.
1. The error occurs before the code executes. This means that even if I try adding "On error resume next" to the code, I still get the error. If I add a breakpoint to the first line of code - the line beginning Private Sub - I STILL GET THE ERROR! I click OK on the error message (the only choice) and THEN the breakpoint stops execution.
2. After I click OK on the error message, the code then works fine - the form I want (frmOrderItemDetails) pops up, allows me to assign items to the order and works perfectly.
3. If I click OK on the error message, then wen frmOrderItemDetails appears I cancel it without adding any items, when I return to this form there are, of course, still no items. But now, if I click on Add Items again, it works perfectly, with no error! But if I navigate off to a different order, then return and click Add Items again, once again I get the No Current Record error.
Someone please save my sanity!!!!
Anyone?!
Thank you so much.
Here's the code:
Code:
Private Sub cmdNewOrderItems_Click()
'Note the current order num as this is used by frmOrderItemDetails
'If the order part has been created but there are no items on it,
' this form will have no order ID yet as there is no current record,
' but the parent (container) form will have the order ID, so use that.
If Me.Recordset.RecordCount > 0 Then
'Used for filtering frmOrderItemDetails, and for allowing user to return
'to this order if they navigate elsewhere.
NoteLastID "CurrentOrderID", Me.lngOrderID
Else
NoteLastID "CurrentOrderID", Me.Parent.lngOrderID
End If
DoCmd.OpenForm FormName:="frmOrderItemDetails", windowmode:=acDialog
'Requery list of items to reflect changes made in frmOrderItemDetails
Me.Requery
End Sub
And in case it's relevant (I think not, but you never know), here's the code for NoteLastID:
Code:
Sub NoteLastID(Optional TempVarName As String, Optional TempVarValue As Long)
' Comments:Called in the click events of Nav form buttons etc to note the last ID being unloaded
' Params : TempVarName - the name of the temp var name to populate. If not provided, default for main loaded form is used
' TempVarValue - the value to store. If not provided, the ID on the main loaded form is used
On Error GoTo ErrHandle
If Len(TempVarName) > 0 Then
TempVars.Item(TempVarName) = TempVarValue
Else
Select Case Form_frmFrame.ChildForm.Form.Name
Case "frmCustomersMain"
TempVars.Item("LastCustomerID") = CLng(Form_frmCustomersMain.lngCustomerID)
Case "frmContactsMain"
TempVars.Item("LastContactID") = CLng(Form_frmContactsMain.lngContactID)
Case "frmOrdersMain"
TempVars.Item("CurrentOrderGroupID").Value = CLng(Form_frmOrdersMain.lngOrderGroupID)
Case "frmQuotesMain"
TempVars.Item("CurrentQuoteID").Value = CLng(Form_frmQuotesMain.lngQuoteID)
End Select
End If
ExitHere:
On Error Resume Next
Exit Sub
ErrHandle:
'Log the error
Call LogError(ErrorNum:=Err.Number, ErrorMessage:=Err.Description, _
ErrorSource:="modFormDisplay - NoteLastID & - Line: " & Erl, _
DisplayMessage:=False, _
ErrorNotes:="")
Resume ExitHere
End Sub