Passing ID from Form A to Form B and closing Form A

P

Pat Dools

Hello,

I have two issues. First, I am attempting to pass along 'Subject_ID' from
the 'fSubject_Info' form to the 'fSession_Info' form and then close the
'fSubject_Info' using the 'OpenArgs' argument of 'DoCmd.OpenForm...'. In the
code below, 'MyArgs' is getting set to the 'Subject_ID' (with a value of 2),
but it is not present for the 'OnLoad' Event of the fSession_Info' form (it
is Null). What is my code missing?

Form A ('fSubject_Info'):

Private Sub CommandOpenVisitForm_Click()
Dim MyArgs As Integer
MyArgs = Me.Subject_ID.Value
If Len(Me.Subject_LName.Value & "") = 0 Then
MsgBox "You must enter a value into Last Name."
Me.Subject_LName.SetFocus
ElseIf Len(Me.Race_ID.Value & "") = 0 Then
MsgBox "You must enter a value into Race."
Me.Race_ID.SetFocus
ElseIf Me.NewRecord = False Then
DoCmd.OpenForm "fSession_Info", , , MyArgs, acAdd
Call ClearControls(Me)
DoCmd.GoToControl "Subject_ID"
End If

Form B (fSession_Info'):

Private Sub Form_Load()
If Not IsNull(Me.OpenArgs) Then
Me.Subject_ID = Me.OpenArgs
End If
End Sub

End result is 'Subject_ID' on 'fSession_INfo' is NULL.

The second issue is that I need to close 'fSubject_Info' once
'fSession_Info' is opened with 'Subject_ID' field being auto-populated from
the 'Subject_ID' field from 'fSubject_Info'. If 'fSubject_Info' remains
open, then when the user goes back to the Switchboard and opens
'fSubject_Info' (for the purpose of entering a new Subject), they get the
form opened with the still-active record. As always, help is greatly
appreciated.

Thank you!
 
V

Volker Neurath

ruralguy said:
Let's start with the fact that the OpenArgs argument is the 7th parameter
in the syntax.

When you're using the annoying DoCmd.OpenForm ,,,, Syntax

But it's not forbidden to use named parameters:

DoCmd.OpenForm "myForm", windowmode:=acDialog, OpenArgs:=.....

Using this syntax it is regarless, where you type the parameter.

Volker
 
V

Volker Neurath

Pat said:
Hello,

I have two issues. First, I am attempting to pass along 'Subject_ID' from
the 'fSubject_Info' form to the 'fSession_Info' form and then close the
'fSubject_Info' using the 'OpenArgs' argument of 'DoCmd.OpenForm...'. In
the code below, 'MyArgs' is getting set to the 'Subject_ID' (with a value
of 2), but it is not present for the 'OnLoad' Event of the fSession_Info'
form (it
is Null). What is my code missing?

Form A ('fSubject_Info'):

Private Sub CommandOpenVisitForm_Click()
Dim MyArgs As Integer
MyArgs = Me.Subject_ID.Value
If Len(Me.Subject_LName.Value & "") = 0 Then
MsgBox "You must enter a value into Last Name."
Me.Subject_LName.SetFocus
ElseIf Len(Me.Race_ID.Value & "") = 0 Then
MsgBox "You must enter a value into Race."
Me.Race_ID.SetFocus
ElseIf Me.NewRecord = False Then
DoCmd.OpenForm "fSession_Info", , , MyArgs, acAdd

Replace your DoCmd - line by

DoCmd.OpenForm "fSessionInfo", OpenArgs:=MyArgs

Of course it is possible to integrate the the "acAdd" Parameter, I apologize
i can't remeber for the correct parameter-name right now and my
Access-related books are in the bureau.
(And at home im using Linux at all)

Volker
 
T

tina

that's correct. but the op chose to use the annoying syntax, and so
ruralguy's instruction was correct and appropriate to the posted code. it is
possible to suggest alternative methods, including explaining why you
believe the alternative is better, without disparaging those that you
personally don't prefer. and it's more courteous.

hth
 
T

tina

you're welcome :)


ruralguy via AccessMonster.com said:
Well said Tina, Thanks.
that's correct. but the op chose to use the annoying syntax, and so
ruralguy's instruction was correct and appropriate to the posted code. it is
possible to suggest alternative methods, including explaining why you
believe the alternative is better, without disparaging those that you
personally don't prefer. and it's more courteous.

hth
Let's start with the fact that the OpenArgs argument is the 7th parameter
in the syntax.
[quoted text clipped - 8 lines]

--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
 
V

Volker Neurath

tina said:
that's correct. but the op chose to use the annoying syntax, and so
ruralguy's instruction was correct and appropriate to the posted code. it
is possible to suggest alternative methods, including explaining why you
believe the alternative is better, without disparaging those that you
personally don't prefer. and it's more courteous.


Sorry, tina, your post has nothing to do with the problem or with what I
said. so it ist to me "a post that's not needed by the world".

Volker
 
P

Pat Dools

Hi, and thank you for pointing out the syntax error. As I progress from
'fSubject_Info' to 'fSession_Info' (and then onto a third form
('fAttendance_Info), I need to then go back to the Swtichboard, click on the
'Enter New Subject' button, and have a fresh 'Subject_Info' form appear. If
'fSubject_Info' stays open, then clicking on the 'Enter New Subject' button
from the Switchboard merely makes the active 'Subject_Info' form appear with
the previous subject, instead of allowing for entry of a new subject. I've
experimented with the 'DoCmd.Close...' function from various spots, but I
haven't found a way to populate the 'Subject_ID' from Form A onto Form B, and
then close Form A.

Thank you for your response!
 
T

tina

thank you, i appreciate that.

as for the code, i agree that style b) below is easier to read, and follow,
with no chance of putting the arguments in the wrong spot. on the other
hand, it's more typing, so more opportunities for typos and syntax errors,
and you lose the advantage of the "automatic list members" that shows the
acceptable variables for each argument.

so each coding method has advantages and disadvantages, and each developer
uses the method that suits him/her best. the syntax most often seen in these
ngs is the a) example below. so it's good that you post the alternative, so
newbies can learn that there *are* alternatives, and make their own choices.

hth
 
T

Tony Toews [MVP]

tina said:
so each coding method has advantages and disadvantages, and each developer
uses the method that suits him/her best. the syntax most often seen in these
ngs is the a) example below. so it's good that you post the alternative, so
newbies can learn that there *are* alternatives, and make their own choices.

Just for grins I once purchased the Access 97 Programming for Dummies
a few years after A97 came out. I was amazed to see this "new"
syntax I'd never known about. There were a few other tips in that
book that have come in handy so I'm glad I spent the money. Even
though I'd been heavily using Access for quite some time by then.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top