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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to control a different open form 1

Status
Not open for further replies.

hondaman2003

Programmer
Mar 3, 2008
202
US
I know how to open a form with a button on a different form. How can I make the newly open for go to the previous record once it's open?
 
I'm sorry, I can't type today, here is the question again without all the typos

I know how to open a form using a button on a different form. How can i make the newly openned form go to the previous record once I have it openned?
 
Basically form 1 opens form 2 by clicking a button. The button is actually filtering form 2 based on information in form 1. Form 2 by default opens to a new record all the time. When the form is filtered it will only have one result everytime, but then it will go to a new record, I want it to go to the previous record which is the only other record in the form at the time that it's openned.

I need to have form 2 open to a new record for another purpose. I was hoping to not have to create a new form and just use form 2 for multi-purposes.
 
I just checked out the posting you have there. I am using the openargs to filter the form when it's open. The trouble is, its still going to a new record. So it will filter showing the only result, then move to the new record. This is where I want to move it back to the previous record if possible.
 
its still going to a new record
Which code does that ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
This same for is used to enter new data also. The "on load" event has the command "DoCmd.GoToRecord , , acNewRec
 
So, don't do it when you don't want to go to a new record.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
This is where I'm having trouble. I was thinking I would like to make it move back to the previous record but I don't know how. Can you show me how to make it move to a new record only in certain situations directly when it's openned?
 
What is the actual code of the Open and Load event procedures ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The load event for form 2 (the form that being openned from another form is:

DoCmd.GoToRecord , , acNewRec

The command is the is used to open it is:

DoCmd.OpenForm "Nexavar - patients", acNormal, , "[ID]='" & rsPatient![ID] & "'
 
To reiterate, see the form OpenArg property. There are many related postings in this forum and VBA help used to give excellent examples.

By placing something similiar to the following in Form2's Open event, you can use Form2 to view a whichever existing record you specify or open to a new record.

Code:
Dim rs As DAO.Recordset
Dim lngRID As Long
    Set rs = Me.RecordsetClone
    If Not IsNull(Me.OpenArgs) Then  'record is being edited
        lngRID = CLng(Me.OpenArgs)
            rs.FindFirst "RID = " & lngRID
        If Not rs.NoMatch Then
            Me.Bookmark = rs.Bookmark
        End If
    Else   'a new record is being created
        DoCmd.GoToRecord , , acNewRec
    End If
    rs.Close
    Set rs = Nothing

Cheers, Bill
 
I'm sorry formerTexan, I assumed you were talking about the "where condition". I figured out exactly how to use the open args and my problem has been fixed now. Thank you for everything!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top