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 / March 2005

Tip: Looking for answers? Try searching our database.

Carry value of variable from one Form to another

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Parker - 09 Mar 2005 21:41 GMT
This is probably a simple question, but how do I keep the defined value for a
variable and use it in another form?

I have a variable named 'PartNoToAdd' that is set in one form when the given
'PartNo' is not in the 'Inventory' Table. (Set PartNoToAdd = Me.PartNo) I
then open a form that asks if the user would like to add the part to
inventory with two buttons 'Yes' and 'No'.  The 'Yes' button opens a 'AddInv'
Form where there is a combo box that I want to auto-fill with the given
'PartNoToAdd'.  I can get it to set the variable correctly, but when I call
it again in the 'AddInv' Form, it is empty.

I've tried declaring it in the 'general declarations' and tried setting it
with both 'Public' and 'Static' according to the help files, but it always
come up empty.

Any ideas?

Thanks in advance for any help!

Parker
Marshall Barton - 09 Mar 2005 23:54 GMT
>This is probably a simple question, but how do I keep the defined value for a
>variable and use it in another form?
[quoted text clipped - 10 lines]
>with both 'Public' and 'Static' according to the help files, but it always
>come up empty.

You'd better post the relevant code from both forms.  I
can't quite make out what you're doing, but your use of SET
...  leads me to think you're doing something different than
what I understood your words to mean.

Signature

Marsh
MVP [MS Access]

Parker - 10 Mar 2005 18:03 GMT
Ok, sorry about the confusion, here are the basics:
 'TblInventory' Table - PartNo (Text), Description (Text), UnitOfMeasure
(Text).
 'TblPurchases' Table - PONo (Text), Vendor (Text), Date (Date/Time),
PartNo (Text), QtyOrdered (Number - Double).
 'QryAddPurchase' - SELECT TblPurchases.PONo, TblPurchases.Vendor,
TblPurchases.Date, TblPurchases.PartNo, TblInventory.Description,
TblInventory.UnitOfMeasure, TblPurchases.QtyOrdered
FROM TblInventory RIGHT JOIN TblPurchases ON TblInventory.PartNo =
TblPurchases.PartNo
WHERE (((TblPurchases.PONo)=[Forms]![FrmAddPurchase].[Combo12]));

 'FrmAddPurchase' Form - (Based on 'QryAddPurchase')
Since it looks up the description
Description On Enter:
Private Sub Description_Enter()
   If IsNull(Me.Description) Then
       Static PartNoToAdd As Variant
       Set PartNoToAdd = Me.PartNo
       DoCmd.OpenForm ("FrmAddInvFly")
   End If
   Me.QtyOrdered.SetFocus
End Sub

 'FrmAddInvFly' Form is just a simple switchboard with two buttons ('Yes'
and 'No').  On click of 'Yes', opens 'FrmAddInv'

 'FrmAddInv' On Open:
Private Sub Form_Open(Cancel As Integer)
   If Not IsNull(PartNoToAdd) Then
       Me.Combo24 = PartNoToAdd
   Else
       Me.Combo24 = Null
   End If
   DoCmd.GoToRecord , , acNewRec

I threw a break point here and the 'PartNoToAdd' is empty.
I just want the PartNo given in the 'FrmAddPurchase' From to carry through
and be automatically entered into the 'FrmAddInv' Form so the user doesn't
have to re-enter it.

Note:  The line "Static PartNoToAdd As Variant" is just my last attempt at
it, I tried 'Public' and also putting it into the 'general declarations'
section...  All had the same result.

Thanks again!

Parker

> >This is probably a simple question, but how do I keep the defined value for a
> >variable and use it in another form?
[quoted text clipped - 15 lines]
> ....  leads me to think you're doing something different than
> what I understood your words to mean.
Marshall Barton - 10 Mar 2005 19:04 GMT
>Ok, sorry about the confusion, here are the basics:
>  'TblInventory' Table - PartNo (Text), Description (Text), UnitOfMeasure
[quoted text clipped - 40 lines]
>it, I tried 'Public' and also putting it into the 'general declarations'
>section...  All had the same result.

Since the declaration of the PartNoToAdd variable in inside
a procedure, it is not available outside the procedure (this
is called local scope).  To make it available to the
remainder of the same module is thould be declared a Private
at the module level (before the first Sub or Function
statement).  And to make it available outside the module,
the declaration needs to be Public at the module level.

Now, you need to be aware that there are two kinds of
modules, Class modules and Standard modules.  A module level
Public variable in a standard module is available to all VBA
code in your project and you can use it as you would use any
variable.

A Public, module level variable in a class module is a
Property of the class (in your case the form's class) and
can be used by referencing the class object.  Again, in your
case,  Forms!theform.variablename.

A different way of achieving your objective is to just get
the value of the combo box without using a variable.

 'FrmAddInv' On Open:
Private Sub Form_Open(Cancel As Integer)
   If Not IsNull(PartNoToAdd) Then
       Me.Combo24 = Forms!FrmAddPurchase.Combo12
        . . .

Signature

Marsh
MVP [MS Access]

 
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.