Hi all,
I am having a problem moving to the correct subform record when opening the main form using a DLookup routine. What I want to do is open a form which holds client details which has a subform which displays order details.
The user enters an order number into a search form, clicks a button and my mainform opens at the client record which owns that unique order number and the subform displays the order record defined by that order number.
The code below opens the main form fine, but does not move to the correct subform record. Any ideas what's wrong with my code?
txtOrderNum is the field on my search form, frmFindOrder frmContactInformation is the main form and frmOrders1subform is the order subform
cheers! Robbo ;-)
I am having a problem moving to the correct subform record when opening the main form using a DLookup routine. What I want to do is open a form which holds client details which has a subform which displays order details.
The user enters an order number into a search form, clicks a button and my mainform opens at the client record which owns that unique order number and the subform displays the order record defined by that order number.
The code below opens the main form fine, but does not move to the correct subform record. Any ideas what's wrong with my code?
txtOrderNum is the field on my search form, frmFindOrder frmContactInformation is the main form and frmOrders1subform is the order subform
Code:
Public Sub Command0_Click()
On Error GoTo err_command0_click
Dim intCustomer As Integer
Dim intOrderNum As Integer
intOrderNum = Me.txtOrderNum
intCustomer = DLookup("CustomerID", "tblOrders1", "OrderNumber=" & intOrderNum)
DoCmd.OpenForm "frmContactInformation", , , "[CustomerID]=" & intCustomer
DoCmd.Close acForm, "frmFindOrder"
Forms![frmContactInformation].frmOrders1subform.RecordsetClone.FindFirst "[OrderNumber]=" & intOrderNum
Forms![frmContactInformation].frmOrders1subform.Bookmark = Forms![frmContactInformation].frmOrders1subform.RecordsetClone.Bookmark
GoTo Exit_command0_click
err_command0_click:
'err 94 is improper use of null value
If Err.Number = 94 Then
MsgBox "There is no order corresponding to the number you have entered." & vbCrLf & vbCrLf & "Please check and try again.", vbExclamation, "Order Number Not Found"
Me!txtOrderNum.Value = null
Me!txtOrderNum.SetFocus
Else:
Exit Sub
End If
cheers! Robbo ;-)