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

Go to specific record in a form 1

Status
Not open for further replies.

WaltLukeIII

Programmer
Jun 28, 2000
199
US
I want to go to a specific, chosen by user, in one form from another. and I don't want to put a filter on the form and eliminate the other records from view. I would also like to do this without writing a small loop with if statements.

basically I am looking for a "GoTo" command that allows for variables.

Walt III
SAElukewl@netscape.net
 
How are ya WaltLukeIII . . . .
[blue]I would also like to do this without writing a small loop with if statements.[/blue]
Realize, you can't do what you want without some kind of [blue]Find/LookUp[/blue] in your code. Even if you use the [blue]DoCmd.GotoRecord[/blue] method, you still have to find the record first! Following is code you can adapt for your needs:
Code:
Dim frm As Form, rst As DAO.Recordset
   
If Not IsOpenFrm("[purple]DependantFormName[/purple]") Then
   DoCmd.OpenForm "[purple]DependantFormName[/purple]"
End If
   
Set frm = Forms![purple]DependantFormName[/purple]
Set rst = frm.RecordsetClone
   
rst.FindFirst "[blue]CommonFieldName[/blue] = " & Me![blue]CommonFieldName[/blue]
frm.Bookmark = rst.Bookmark
   
Set rst = Nothing
Set frm = Nothing
Note: The code does'nt check if the recordset for the Dependant Form is empty, nor does it check wether or not the record is found. Also, if you decide to use the beginning code which determines id the Dependant Form is open or or not, you'll need to put the following function in a module, in the modules window:
Code:
Function IsOpenFrm(frmName As String) As Boolean
   Dim cp As CurrentProject, Frms As Object
   
   Set cp = CurrentProject()
   Set Frms = cp.AllForms
   
   If Frms.Item(frmName).IsLoaded Then
      If Forms(frmName).CurrentView > 0 Then IsOpenFrm = True
   End If
   
   Set Frms = Nothing
   Set cp = Nothing

End Function
Now . . . if you put the code (1st code window) in the [blue]On Current[/blue] event of the [blue]Independant Form[/blue], the [purple]Dependant Form[/purple] will synchronize whenever you change record. If this is not desireable, you could do something like add a command button. Here you would put the code in the [blue]On Click[/blue] event, whereby your operation would be to select a record, then click the button.

Hope this helps!


cal.gif
See Ya! . . . . . .
 
Escellent Code. the bookmark was exactly the help I was looking for. Nice signiture by the way.

Thanks

Walt III
SAElukewl@netscape.net
 
WaltLukeIII . . . .

I hate leaving code without correcting for errors . . .
Would you like to have the code with error correction?, or do ya wanna do it yourself?

cal.gif
See Ya! . . . . . .
 
Because I am the administrator of the table I know how it is setup. so I do usually handle errors, in this I am using the primary key to the table so if there were an error the data would have to be corrupted.

Thanks

Walt III
SAElukewl@netscape.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top