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!

Goto a record on another form

Status
Not open for further replies.

kenaida

Programmer
Jul 9, 2001
3
GB
Hi, I have a form called Main and one called ClientFinder. ClientFinder has a listbox and I have the code that when you click on a client, it saves the clientID and closes the ClientFinder screen and sets the focus to the Main form. How do I get the Main form to goto the Client that I have the ID for? I tried creating a public function on the Main form that I could reference from the ClientFinder but it did not recognise it.

Yours worryingly,

Kenaida
 
Create a module that has the statement:
Public intSelectedClientID as Integer

This gives you a public variable that you can use to carry the value of the Client ID from one form to another.

Set intSelectedClientID to the value selected in the list box you mention.

In the OnOpen property of your main form, put the following code:

If intSelectedClientID > 0 then
me.FilterOn = True
me.Filter = "[ClientID] = " & intSelectedClientID
me.requery
End If

This will display only the selected client. If you want to give the user the option to clear the filter, put a command button on the footer (or header) of your Main Form, with the following code behind the OnClick property:

intSelectedClientID = 0
me.Filter = ""
me.requery

By the way, you could just put the client listbox in the footer (or header) of your main form and add another button (Find Client) that for the OnClick property executes similar code to the first set of code above that filters for the one client.
 
The answer, in a round about way is to NOT do what you're doing. - Well - do it another way round at least.

Like this instead:-
Have all the useful code in the ClientFinder form

Private Sub ListBox_AfterUpdate()
'Set Focus to ClientControl on Main Form
Forms!Main!ctlClient.SetFocus
' Go to the target record
DoCmd.FindRecord Forms!ClientFinder!ListBoxName
' NOW close the ClientFinder
DoCmd.Close acForm ,"ClientFinder"

End Sub

This way even avoids the need for a Global Variable.


QED?

G LS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top