Transfering data from text box on one form to another form using vb

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Hitman
    New Member
    • Mar 2008
    • 1

    Transfering data from text box on one form to another form using vb

    Hi Everyone,

    I have a little bit of problem with my database. I have a textbox ( the name of the textbox is location) on one form and 1 command button. I also made another form with 1 textbox (the name of the textbox is designator) . I want to use vb on programming the command button. All I want to happen is that after I place some text on the texbox (location) I click the command button and the text on (location) will be copied to the other textbox(designa tor) which is located on the other form. I already tried declaring a global variable and save the data on this variable but I couldnt use the variable on other form even thought I set it as public. I would appreciate any help. Thanks in advance.
  • rdsandy
    New Member
    • Oct 2007
    • 20

    #2
    Hi Hitman,

    Im not sure how you set up your global variable and how you used it, but i'll suggest how I do it. Make a new Module (by going on the Module section of the database window and clicking new). Then type in:

    Code:
    Global yourVariableName As yourDataType
    where yourVariableNam e is the name of the variable, and yourVariableTyp e is the data type for it (ie: for text use String etc). Then on the AfterUpdate of your text box put:

    Code:
    yourVariableName = Me.Location
    Now, from here if you are only setting whatever is in location to be in designator (i think it was called) just once (ie, set it when you open the form), then all you have to do is set the text box to the global variable on form open, like:

    Code:
    Private Sub Form_Open(Cancel As Integer)
    
    Me.Designator = yourVariableName
    
    End Sub
    and thats it, you don't really need the command button if its only used to set designator to whatever locations is.

    Hope this helps,

    Andrew

    Comment

    • rdsandy
      New Member
      • Oct 2007
      • 20

      #3
      After re-reading your post, it sounds like you have both forms open at the same time. I just made a dummy database, made two forms, one called Location, with a text box called Location, and a command button called cmbCopy, and another form called Designator with a text box called Designator. I made a new module and the code in there looks like this:

      Code:
      Option Compare Database
      
      Global copyText As String
      On the Location form I have this code:

      Code:
      Option Compare Database
      
      Private Sub cmbCopy_Click()
      
          copyText = Me.Location
          
          Forms!designator!designator = copyText
         
      End Sub
      When I type something in Location text box and click the button, it appears in the Designator text box, so it should work for you.

      Hope this helps,

      Andrew

      Comment

      Working...