By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,466 Members | 1,756 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,466 IT Pros & Developers. It's quick & easy.

Access 97 - Passing a field value to another form

P: n/a
Hi,

I need to pass the value held in a field in one form and have it
appear in another form. I specifically don't want to have to refer to
the original form name as it has passed, because I want the second
form to be accessed from several different places.

I've tried declaring a public variable:

Public gempID As Integer

at the top of the module for the first form,
but the field in the second form then just displays #Name?, even
though the name in the second form is exactly the same as the name of
the variable.

Any suggestions?
Regards,
Bernard D
Nov 13 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Bernard Davis" <bdavis(deletethis)@castlecs.co.uk> wrote in message
news:99********************************@4ax.com...
Hi,

I need to pass the value held in a field in one form and have it
appear in another form. I specifically don't want to have to refer to
the original form name as it has passed, because I want the second
form to be accessed from several different places.

I've tried declaring a public variable:

Public gempID As Integer

at the top of the module for the first form,
but the field in the second form then just displays #Name?, even
though the name in the second form is exactly the same as the name of
the variable.


I think you'd need to declare a Global variable in a module.

Regards,
Keith.
www.keithwilby.com
Nov 13 '05 #2

P: n/a
On Thu, 5 May 2005 15:54:29 +0100, "Keith"
<ke*********@baeAWAYWITHITsystems.com> wrote:
"Bernard Davis" <bdavis(deletethis)@castlecs.co.uk> wrote in message
news:99********************************@4ax.com.. .
Hi,

I need to pass the value held in a field in one form and have it
appear in another form. I specifically don't want to have to refer to
the original form name as it has passed, because I want the second
form to be accessed from several different places.

I've tried declaring a public variable:

Public gempID As Integer

at the top of the module for the first form,
but the field in the second form then just displays #Name?, even
though the name in the second form is exactly the same as the name of
the variable.


I think you'd need to declare a Global variable in a module.


Thanks, yes I know that.
Public = Global (as far as I know).

The problem is I've tried that as well,
Public gempID As Integer
at the top of a module called PublicVariables.

I can then assign a value to that variable, but it is ignored in the
second form.

What I'm trying to do is allow the user to create notes about a record
and I need to pass the record ID so that the notes will refer back to
the correct record subsequently.
I can explicitly refer to the ID by using the originating form name -
and that works, but as the notes form can be called from a number of
different places I don't want to have to keep building notes forms,
each one of which refers explicitly to the originating form (if that
makes sense).

Regards,
Bernard D

Nov 13 '05 #3

P: n/a
"Bernard Davis" <bdavis(deletethis)@castlecs.co.uk> wrote in message
news:k7********************************@4ax.com...

I think you'd need to declare a Global variable in a module.


Thanks, yes I know that.
Public = Global (as far as I know).

The problem is I've tried that as well,
Public gempID As Integer
at the top of a module called PublicVariables.

I can then assign a value to that variable, but it is ignored in the
second form.

Public, Global, whatever :o) the point is that it needs to be in a module
and you need to:

1 - Set the variable using your first form (you seem to know that already);
2 - Set the control on the second form as appropriate.

I just tried it by setting the Public/Global variable in a form's On Open
event and then retrieving it via a second form's On Current event and it
worked fine:

Private Sub Form_Current()

Me.txtMyTextBox = gempID

End Sub

I've just re-read the last bit of your post and it seems that what you're
trying to do could be done for free by Access by setting up a query
containing the tables for both forms - they must be related, surely?

Regards,
Keith.
Nov 13 '05 #4

P: n/a
When you want to open the second form, from say a button click, use
code like this on the button in the first form:

DoCmd.OpenForm stDocName, acNormal, , , , , Me.boxFID

Where stDocName is the name of the second form and Me.boxFID is the
field that contains the value you want to pass.
The commas are all needed, they are for different options when opening
a form.

Then use code like this in the 'on open' event of the second form:

If Not IsNull(Me.OpenArgs) Then
Me.boxFinder.Value = Me.OpenArgs
Me.Requery
End If

Me.OpenArgs will be equal to whatever value you passed from the event
in the first form.

Nov 13 '05 #5

P: n/a
On 5 May 2005 11:48:08 -0700, "Nunya Biznas" <Nu*********@comcast.net>
wrote:
When you want to open the second form, from say a button click, use
code like this on the button in the first form:

DoCmd.OpenForm stDocName, acNormal, , , , , Me.boxFID

Where stDocName is the name of the second form and Me.boxFID is the
field that contains the value you want to pass.
The commas are all needed, they are for different options when opening
a form.

Then use code like this in the 'on open' event of the second form:

If Not IsNull(Me.OpenArgs) Then
Me.boxFinder.Value = Me.OpenArgs
Me.Requery
End If

Me.OpenArgs will be equal to whatever value you passed from the event
in the first form.

Many thanks, this was the clue I needed. It now works perfectly. The
real problem was that I was opening this second form from about 12
different places and couldn't face having to create 12 different
versions of it.

Regards,

Bernard D
Nov 13 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.