Set a value in VB

G

Guest

I know how to SetValue in a macro. I'd appreciate someone explaining to me
simply how to do the equivalent in VB...

Form1 is open. Form1 has a primary key field "Form1ID"

Form2 is opened from Form1. Form2 has a field "Form1Link"

When opening Form2 to add a new record, "Form1Link" needs to be given the
same value as "Form1ID"

PS - In Access Help, I can find the parameters for SetValue. In Vb help,
there is nothing. Nor is there any link that I could see. Is there an easy
way of going from a macro help page to the equivalent VB help page?
 
G

Guest

On the Open command you can send an open args that includes the Id from form1

DoCmd.OpenForm "Form2Name", , , ,acFormAdd, , Me![Form1ID]

===================================
On the load event of the second form write the code

Me![Form1Link] = Me.OpenArgs
 
G

Guest

Thanks for the reply. I have added the code and it works. But it raises for
me a number of questions as a learner who wants to understand, not just copy…

1. What does “Me†mean in VB code? I’ve seen it often, but there is no
reference to it in my help files.

2. Now that I have an event procedure attached to the load event of Form2,
does that mean Form2 will always open to a new record and set the values?
What about when I want to open Form2 just with existing records?

3. I still don’t have a clue about setting values generally in code. What
if I want to set the value of more than one control? Or if I want to set a
value after the form is open? Are there any general guidelines? Where might
I look in Help or for articles online?

--
PeterK


Ofer said:
On the Open command you can send an open args that includes the Id from form1

DoCmd.OpenForm "Form2Name", , , ,acFormAdd, , Me![Form1ID]

===================================
On the load event of the second form write the code

Me![Form1Link] = Me.OpenArgs


--
Please respond to the group if your question been answered or not, so other
can refer to it.
Thank you and Good luck



PeterK said:
I know how to SetValue in a macro. I'd appreciate someone explaining to me
simply how to do the equivalent in VB...

Form1 is open. Form1 has a primary key field "Form1ID"

Form2 is opened from Form1. Form2 has a field "Form1Link"

When opening Form2 to add a new record, "Form1Link" needs to be given the
same value as "Form1ID"

PS - In Access Help, I can find the parameters for SetValue. In Vb help,
there is nothing. Nor is there any link that I could see. Is there an easy
way of going from a macro help page to the equivalent VB help page?
 
R

Rick Brandt

PeterK said:
Thanks for the reply. I have added the code and it works. But it
raises for me a number of questions as a learner who wants to
understand, not just copy.

1. What does "Me" mean in VB code? I've seen it often, but there is
no reference to it in my help files.

The current VBA "container". If the code is running in a form's module then Me
refers to the form in the same way that Forms!NameOfForm does. It is nicer
though because you can change the name of the form and the code doesn't break
and/or you can copy code from one form to another and not have to worry about
the name being different.
2. Now that I have an event procedure attached to the load event of
Form2, does that mean Form2 will always open to a new record and set
the values? What about when I want to open Form2 just with existing
records?

It is the acFormAdd argument of the OpenForm method that is causing Form2 to go
to a new record. If you open Form2 in other code without using acFormAdd then
it will show existing records. If you know you will do this then you need to
change your OnLoad code so that it only uses OpenArgs when OpenArgs actually has
a value.

If Len(Nz(Me.OpenArgs, "")) > 0 Then
Me![Form1Link] = Me.OpenArgs
End If
3. I still don't have a clue about setting values generally in code.
What if I want to set the value of more than one control? Or if I
want to set a value after the form is open?

Me.ThisControl = SomeValue
Me.ThatControl = SomeOtherValue
(as many more lines as you want)

Where you obtain the values will vary from one circumstance to the next. The
form has many events and many of those events could be used to run code to set
the value of a control. Which event is appropriate is again going to vary from
one circumstance to the next.
Are there any general
guidelines? Where might I look in Help or for articles online?

There should be a topic on Form Events. That would be a good place to start.
 

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