Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / December 2005

Tip: Looking for answers? Try searching our database.

Set a value in VB

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
PeterK - 29 Dec 2005 22:08 GMT
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?

Signature

PeterK

Ofer - 29 Dec 2005 22:55 GMT
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

Signature

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

> I know how to SetValue in a macro.  I'd appreciate someone explaining to me
> simply how to do the equivalent in VB...
[quoted text clipped - 9 lines]
> 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?
PeterK - 30 Dec 2005 22:43 GMT
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?

Signature

PeterK

> On the Open command you can send an open args that includes the Id from form1
>    
[quoted text clipped - 18 lines]
> > 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?
Rick Brandt - 30 Dec 2005 23:57 GMT
> 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.

Signature

I don't check the Email account attached
to this message.     Send instead to...
RBrandt    at       Hunter      dot      com

TC - 30 Dec 2005 01:48 GMT
> Form1 has a primary key field "Form1ID"

Forms do not have primary keys. Only tables have primary keys.

HTH,
TC
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.