Change Parameter for Query depending on which form the query was called from (1 Viewer)

patkeaveney

Registered User.
Local time
Today, 01:38
Joined
Oct 12, 2005
Messages
75
Hi

I have a form called View Courses

This form is displayed when the user clicks a button on either
the Viewstudent form, or the Searchstudent form.

The View Courses form is based on a query, which uses the student ID from the calling form.

I have created 2 versions of the Viewcourses form (with the parameter on version one being student ID form Viewstudent form and version two being studen ID from the Searchstudent form).

Is there a way I can use just one version of the View courses form, with the correct parameter being picked up depending on which form the button was clicked on.

Thanks

Pat
 

DCrake

Remembered
Local time
Today, 01:38
Joined
Jun 8, 2005
Messages
8,632
Simple Software Solutions

In short Yes

First create a Public variable called StrStudentID As String or IntStudentID as Long (depending on the type of field is being used)

Then on each of the buttons OnClick event pass the parameter value to the above variable.

Then on the OnLoad of the View Courses form enter the following:

Me.Filter = "Select * From QueryName Where StudentId=" & StrStudentID
Me.FilterOn = True

This will then use the correct student from your underlying query.

Code Master::cool:http://www.icraftlimited.co.uk
 

patkeaveney

Registered User.
Local time
Today, 01:38
Joined
Oct 12, 2005
Messages
75
Thanks for the help

For the vaiable to be available across the different forms
where in the code do I decalre the PUBLIC variable
(Can it be declared in one of the forms code)

Thanks in advance
 

DCrake

Remembered
Local time
Today, 01:38
Joined
Jun 8, 2005
Messages
8,632
Simple Software Solutions

Normally, when declaring variable you should consider how long you want the variable to survive.

If you want the variable to available at any point during the time the app is open then it needs to be delared as the app is opened. To do this in you start up module, if you have on, at the very top of the declarations enter

Public [YourVariableName] As [VariableType]

If you do not have a module, which is unlikely, I suggest you create one - say - ModPublics - and place it in there.

Create a public function called AppPublics - for example - and within this function pass a default value to the variable - even if it is only a 0 or a empty string.

Then on you first splash screen on the OnLoad of your form place a line of code in there:-

Call AppPublics

This will ensure that the vaiable is declared and has a default value.

If you only want a variable to be active during the life of an open form then declare the variable in the declarations section of the code within the chosen form.


Hope this is clear enough

David
 

Users who are viewing this thread

Top Bottom