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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Pass variable through forms? 1

Status
Not open for further replies.

tanolalano

Technical User
Jul 7, 2003
27
0
0
IT
Hi all,
I Have a form with a click button that prompt a message box for choosing to send the value of some controls in the form to an addnew DAO(VbNo) or open a popup form(unbound) and change some value to send to the addnew DAO (VbYes).
As Well, I haven't found the right solution searching in the forum.
I try to dim public var on the popup form but how I catch it in the form?
Here my code
Code:
[COLOR=red]'********On popup form ************** [/color]
Public pag_ord As Boolean
Public Caus As String
Public impor As Currency

Private Sub Form_AfterUpdate()
   Caus = Forms![imp_nota]![Causale]
   pag_ord = Forms![imp_nota]![pagato]
   impor = Forms![imp_nota]![import]
End Sub
Private Sub Close_Click ()
   Me.visble= false
end sub
[COLOR=red]'**********Form *********[/color]
Private Sub save_Click()

If vbYes = MsgBox("ect....")
     DoCmd.OpenForm "popupForm", , , , , acDialog
[COLOR=red]'then i set the var on the popup
     'but How I catch them and continue the code?
     ' i try this code but nothing happen[/color]
     Caus_frm1 = "Caus"
     pag_frm1 = pag
     impor_frm1 = import
     DoCmd.Close , "popupForm"
         Set db = CurrentDb()
         Set rs1 = db.OpenRecordset("Ordini", dbOpenDynaset)
              rs1.AddNew
              rs1![Totale] = impor_frm1
              rs1![pagato] = pag_frm1
        'etc etc
Else
        'Standard Dao Add
         Set db = CurrentDb()
         Set rs1 = db.OpenRecordset("Ordini", dbOpenDynaset)
              rs1.AddNew
              rs1![Totale] = Me.totale
              rs1![pagato] = me.pagato
        'etc etc
End if

Any Help would be appreciated
 
Suggest you put in some debug.print statements in the code. Are impor, import, impor_frm1 all separate variables?
try addin option explicit below 'Option Compare Database' in each of the forms and this too will help find the errors.


Ian Mayor (UK)
Program Error
Always make your words sweet and nice. Because you never know when you may have to eat them.
 
I known that I typed the wrong name of var in the code posted...
I want to know if i'm in the right way!
Thanks
 
How are ya tanolalano . . .

[ol][li]Move the public variables to a [blue]module[/blue] in the [blue]modules[/blue] window.[/li]
[li]The [blue]Click[/blue] event of the form would look like:
Code:
[blue]Private Sub save_Click()
   Dim db As DAO.Database, rs1 As DAO.Recordset
   
   If MsgBox("Your Message") = vbYes Then
        DoCmd.OpenForm "popupForm", , , , , acDialog
        [green]'Because of acDialog code stops here until popup is closed.
        'Popup updates public variables before closing.[/green]
   Else
        [green]'Form updates public variables[/green]
   End If
   
   Set db = CurrentDb()
   Set rs1 = db.OpenRecordset("Ordini", dbOpenDynaset)
   
   rs1.AddNew
   [green]'rs1 assignments to public variables here[/green]
   rs1.Update
   
   Set rs1 = Nothing
   Set db = Nothing
   
End Sub[/blue]
[/li]
[li]Since your [blue]popup is unbound[/blue] add a save button that sets the public variables before closing.[/li][/ol]
[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Thanks AceMan...you're my guro ;)

I've moved the public variable to a module before You've posted. All worked.
But now, I follow your suggestion and put a save button on popup form to set Pub vars and then a close btn to quit the form.

Thanks all

PS now I have a new question....i will post new thread
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top