Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Public statement problem 1

Status
Not open for further replies.

ftook

Programmer
Dec 4, 2006
80
GB
I have 2 forms (forma, formb) and i have declared public variable as integer in forma (dtype), based upon button press in forma set dtype to 1 or 2 and open formb, then when selection made on combo box set controla to 1 or 2 (value of dtype), doesnt seem to set controla and also has affect on other items i have set on afterupdate of combo box,

any ideas pls ?
 
Have you considered using OpenArgs?

Otherwise, please post some code.
 
not too sure on openargs but heres code from forma and formb

FORMA ***************

Public dtype As Integer

Private Sub door_Click()
dtype = 1
DoCmd.OpenForm "Order Form"
End Sub

Private Sub doortl_Click()
dtype = 2
DoCmd.OpenForm "Order Form"
End Sub

FORMB ***************

Private Sub Customer_AfterUpdate()
Me.dt = dtype
If Me![Order No] < 1 Then
Me![Order No] = DMax("[Order No]", "Order Details") + 1
End If
Me![Gorder] = DMax("[Gorder]", "Glass Header")
Me![Order Date] = Now()
End Sub
 
This is a module level variable:

"Module-level variables have a lowercase "m" prefix and are declared in the Declarations section of a module by using the Dim or Private statement. They are visible to any procedure within the module in which they are declared." - Microsoft

It will not be available to FormB.

If you say:

[tt]DoCmd.OpenForm "Order Form", , , , , , Dtype[/tt]

You have an OpenArg that can be referred to in FormB:

[tt]FORMB ***************

Private Sub Customer_AfterUpdate()
Me.dt = Me.OpenArgs[/tt]

 
How are ya ftook . . .

. . . and this:
Code:
[blue]Me![purple][b][i]TextboxName[/i][/b][/purple] = Forms!forma.dtype[/blue]

Calvin.gif
See Ya! . . . . . .
 
. . . hit submitt too soon.

Using a public variable in form [blue]requires the form to be open[/blue]. To circumvent this just [blue]move the variable[/blue] to a module in the modules window.

The [blue]OpenArgs[/blue] alternative presented by [blue]Remou[/blue] is also a good one. However OpenArgs [blue]only accepts a string[/blue] and therefore two conversions are required. Forma looks like:
Code:
[blue]   DoCmd.OpenForm "Order Form", , , , , , CStr(Dtype)[/blue]
And formb:
Code:
[blue]   Me!dt = CInt(Me.OpenArgs)[/blue]
[blue]Remou's[/blue] method is perferred here as its more secure to pass values than have them sitting out in the open!

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
Thank for the solution - works great !

Private Sub Customer_AfterUpdate()
Me.dt = Me.OpenArgs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top