Cmd buttton open wrong record

Dgavilanes

Registered User.
Local time
Today, 17:54
Joined
Jun 25, 2001
Messages
109
Hi All,

I have form A and form B, in form A I have two cascading combo boxes and a cmd button that once the criteria is selected it open form B in the correct record, however I copy the objects from A to B to eliminate two forms and just using one form, now when the criteria is selected, it will not open the correct record selected in the criteria.

Here is the code that was use in the cmd button in form A

Private Sub Cmd6_Click()
On Error GoTo Err_Cmd6_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmIPSummary"

stLinkCriteria = "[Investment Plan Number]=" & "'" & Me![Investment Plan Number] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Cmd6_Click:
Exit Sub

Err_Cmd6_Click:
MsgBox Err.Description
Resume Exit_Cmd6_Click
End Sub

This code worked before moving it to the second form B

Any help would be greatly appreciated

Dennis
 
Rather than using DoCmd.OpenForm perhaps you should think about using
DoCmd.FindRecord given that you were initially using the code to open Form B from Form A, and that you have now moved the code from Form A to Form B.
 
Thanks for your quick reply, because the criteria is selected from two cascading combo boxes, a cmd button is required to go to the specific record, now this is objects are contained in a single form and it does not filter to the correct record.
When I had two formas A and B it worked fine. Thanks again

Dennis
 
I found the solution to my own question and would like to share it

The code that I'm using is:


Private Sub Cmd6_Click()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[Investment plan Number] = '" & Me![Cbx1] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub

and is working fine

Thanks for your support


Dennis
 

Users who are viewing this thread

Back
Top Bottom