borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (beginer question)Next Topic (Create submenu items at runtime.) New Topic New Poll Post Reply
AndreaVB Forum : VB General : Getting values from a called form
Poster Message
frodo9149
Level: Trainee

Registered: 08-02-2005
Posts: 2

icon Getting values from a called form

Hello,

I am new to visual basic programming, but have been using ObjectPal with Paradox for years. I am using Access 2003 and am trying to call an input form that prompts the user for some data.  The form is being called using the onexit event in a field on the calling form.  I want the value the user inputs on the called form to be placed in a field on the calling form.  I am having much difficulty getting the value to transfer from the called form.  In the Paradox world this is easily resolved with the formreturn procedure.  Is there any way in VB to resolve this issue?  I know there is, I just do not know it at this point.  

Thank you .

08-02-2005 at 04:35 PM
View Profile Send Email to User Show All Posts | Quote Reply
jonybd
Level: Master

Registered: 18-01-2005
Posts: 115
icon Re: Getting values from a called form

Please describe details , with code

____________________________
Telecommunication programmer.
Sip, Isdn - technology.

08-02-2005 at 08:42 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
frodo9149
Level: Trainee

Registered: 08-02-2005
Posts: 2
icon Re: Getting values from a called form

I have 2 forms, one that is a data form and the other an input form for users to enter margins or costs.


On the calling form I have a field called "End Cost" with the following code attached to the onexit event.

Private Sub End_Cost_Exit(Cancel As Integer)

If IsNull(Margin.Value) Or Margin.Value = 0 Then
    
   DoCmd.OpenForm ("FrmMarginInput"), acNormal, acWindoNormal

      
End If

End Sub

The form FrmMarginInput has an unbound box with name nbrmarginvalue and another one called nbradjval.

The following code is attached to the OK button on this form

Private Sub okbutton_Click()

adjval = nbrAdjVal.Value
margvar = nbrMarginValue.Value
MsgBox (margvar) ' view margvar value

DoCmd.Close

MsgBox (margvar) ' view it again
DoCmd.GoToControl ("Margin") ' move to margin field on calling form


End Sub

I am using the msgbox proc to view the variables as I go through the code.

On this module the variables margvar and adjval are declared as Public.  

When the margin input box closes, the program moves to the margin field on the calling form.  On the onenter event on this field the following code is attached.

Private Sub Margin_Enter()
If Margin.Value = 0 Or IsNull(Margin.Value) Then
  MsgBox (margvar), , "Margin Value"
   If IsNull(margvar) Or margvar = 0 Then
     MsgBox ("Cannot set Value"), , ("Warning")
      Else
       Margin.Value = margvar
   End If
  Else
    MsgBox ("Value already entered"), , ("Warning")
End If
End Sub

The value from the input box should show up in the margin field but it does not.  A null value shows instead.

I am perplexed, I hope this helps describe my problem.

Thank you.

08-02-2005 at 08:59 PM
View Profile Send Email to User Show All Posts | Quote Reply
steve_w
Level: Moderator


Registered: 18-04-2003
Posts: 1156
icon Re: Getting values from a called form

Hi

You can create properties in your forms which you can use to transfer data between forms.

See my example below where form2 is where you type in the margins and form1 is the starting form

' form1 code
' controls
' cmdButton called cmdGetMargin
' textbox called txtReturnedMargin

Private Sub cmdGetMargin_Click()

    Dim frm As Form2
    
    Set frm = New Form2
    
    frm.Show 1
    
    txtReturnedMargin.Text = frm.Margin

    Set frm = Nothing

End Sub


'form2 code
' controls
' txtbox called txtMargin
' cmdbutton called cmdExit

Private m_Margin As Double

Public Property Get Margin() As Double
    
    Margin = m_Margin

End Property

Private Sub cmdExit_Click()

    Unload Me

End Sub

Private Sub Form_Load()

End Sub

Private Sub txtMargin_Validate(Cancel As Boolean)

    m_Margin = Val(txtMargin.Text)

End Sub



Steve  

11-02-2005 at 07:00 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB General : Getting values from a called form
Previous Topic (beginer question)Next Topic (Create submenu items at runtime.) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder