Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving through subform records

Status
Not open for further replies.

Robbo1974

Technical User
Jun 1, 2001
151
GB
Hi all,

I have a mainform [frmContactInformation] which has a subform displaying orders for each record [frmOrders1Subform]. The following code is designed to allow a user to enter an order number into a search form and move directly to the order record for that order number. The problem is this: The code opens the mainform fine, but the subform displays the order record at the 'top of the pile' - the first record in the default sort order for the form. Any ideas on how to move through the subform records so that the correct order is displayed?

I had thought of trying to change the linkchild/parent fields property to the ordernumber field, but am not sure how to do this.

Any suggestions will be gratefully appreciated.

Here's the code
Code:
Public Sub Command0_Click()

On Error GoTo err_command0_click

Const dQuote = """"
Dim intCustomer As Integer
Dim strOrderNum As String
Dim strCriteria As String

strOrderNum = Me.txtOrderNum 'text box the user enters order number into
strCriteria = "OldOrderNumber = " & dQuote & strOrderNum & dQuote


'find the customer record that owns the order
intCustomer = DLookup("CustomerID", "tblOrders1", strCriteria)

'open the mainform at the right record
DoCmd.OpenForm "frmContactInformation", , , "[CustomerID]=" & intCustomer DoCmd.Close acForm, "FrmSearchOrder"

'find the right order and bookmark it
Forms![frmContactInformation].frmOrders1subform.RecordsetClone.FindFirst "[OldOrderNumber]='" & strOrderNum & "'"

Forms![frmContactInformation].frmOrders1subform.RecordsetClone.Bookmark = Forms![frmContactInformation].frmOrders1subform.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

End If

Exit_command0_click:

End Sub
Robbo ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top