Is it possible to add data from one form to another?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • araman
    New Member
    • Jan 2008
    • 53

    #1

    Is it possible to add data from one form to another?

    I have a form called enterorders. The form enters data into the orders table. There is a box on the form to type in a phone number. the user can dbl click the phone number field and pull up a customer search form. Is it possible to dbl click the phone number on the search form and have it automatically fill in the phone number field on the enterorders form?

    Thanks
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    Yes.

    It could go something like this:
    Code:
    Private Sub tb_PhoneNumber_DoubleClick()
    
    'error checking
      'Check that we have a phonenumber in the textbox
      If Me.tb_PhoneNumber & "" ="" then
        MsgBox "No phonenumber entered"
        Exit Sub
      End If
    
      'Check that frm_EnterOrder is open
      If Not Currentproject.AllForms("frm_EnterOrder").IsLoaded Then
        'Form is not open, so cannot transfer to form, simply exit
        Exit Sub
      End If
    
      'Ask user if he wishes to transfer phonenumber
        if vbyes=Msgbox("Do you wish to transfer phonenumber: " & me.tb_PhoneNumber & " to your current order?",vbyesno,"Transfer phonenumber?") Then
         Forms("frm_EnterOrder").tb_PhoneNumber=Me.tb_PhoneNumber
       End If
    End Sub
    Now this answers your question, HOWEVER if you spend a few moments reading about database normalisation, you would see why in most cases its a bad idea.

    Why do you record the phonenumber and not the primary key of your customer?

    Comment

    • araman
      New Member
      • Jan 2008
      • 53

      #3
      Thanks, I use the phone number as the key since it will be unique.

      I am using the access 2010 navigation form. when the enter orders form is the subform of that the code does not work. it does work when i open the form without being in the navigation form. do i have to change something like enter orders reference to navigationform. navigationsubfo rm for it to work

      Thanks

      Comment

      • TheSmileyCoder
        Recognized Expert Moderator Top Contributor
        • Dec 2009
        • 2322

        #4
        Yes. The current code is working on the basis that the form is the "top-most" open one, I.e. that it is not embedded as a subform. The reason (from access point of view) is that you can have a form open several times at once, as a subform, and how would access know which subform to reference?

        Replace Main form with the name of your navigation form, and NameOfControlCo ntaingingSubFor m with the name of the control containing your frm_EnterOrder.
        Code:
        Forms("MainForm").NameOfControlContaingingSubForm.Form.tb_PhoneNumber=Me.tb_PhoneNumber

        EDIT: Sorry about the late answer, I must have somehow missed your reply in my mailbox.

        Comment

        • araman
          New Member
          • Jan 2008
          • 53

          #5
          Thanks, I figured it out in short order right after the post

          Comment

          Working...