• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 131
  • Last Modified:

How to Move to a record on a form based on another forms data

I have a main form... On the main form I have a button that brings up a small form named Reservations.  On this Reservations form there is a combo box that searches for a reservation number.  The search is working fine.  The reservation form is a modal... I would like to put a button on the reservation for that says "Go to this record"... when you click the button, the modal- Reservations form closes and the form that is open in the background moves to the id that was in the Reservations form...

I think I know how to do this when the forms are closed but I don't know the coding for the form that is already open.
0
Shaft960
Asked:
Shaft960
  • 5
  • 4
1 Solution
 
Gustav BrockCIOCommented:
On the search form, use this code in OnClick event of the goto button:

    DoCmd.OpenForm "YourBackgroundFormName", , , "ID = " & Me!txtReservation.Value & ""
    DoCmd.Close acForm, Me.Name

Adjust ID to the name of the Reservation field on the background form.
Adjust txtReservation to the name of your textbox on the search form.

If reservation number is Text, apply single quotes:

    DoCmd.OpenForm "YourBackgroundFormName", , , "ID = '" & Me!txtReservation.Value & "'"
    DoCmd.Close acForm, Me.Name

/gustav
0
 
Shaft960Author Commented:
Thanks... I know that was kinda simple but I was blowing it.... Nice job
0
 
Shaft960Author Commented:
Is there a way that it will go to the forms and show all of the records but just be on the record that I wanted... It is going there but it shows filtered records...
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
Gustav BrockCIOCommented:
Yes. You can either just push the Filtered button at the bottom of the form.
Or run this code from the button:

    DoCmd.SelectObject acForm, "YourBackgroundFormName"
    DoCmd.SearchForRecord  , , , "ID = " & Me!txtReservation.Value & ""
    DoCmd.Close acForm, Me.Name

/gustav
0
 
Shaft960Author Commented:
I am getting error messages now.. Method or data member not found
0
 
Shaft960Author Commented:
DoCmd.SearchForRecord , , , "ID = " & Me![ID]
0
 
Gustav BrockCIOCommented:
Oh, it use the wrong "Me":

     Dim SearchID As Long
     SearchID = Me!ID.Value
     DoCmd.SelectObject acForm, "YourBackgroundFormName"
     DoCmd.SearchForRecord  , , , "ID = " & SearchID & ""
     DoCmd.Close acForm, Me.Name

 /gustav
0
 
Shaft960Author Commented:
Error pops up and it highlights the SearchForRecord text...
0
 
Gustav BrockCIOCommented:
Then something else is going on.
The sample works (right-click, Save As ..., change extension to accdb, Ok).

/gustav
DbSearch.accdb
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now