469,167 Members | 1,979 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,167 developers. It's quick & easy.

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

53
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
Jan 24 '11 #1

✓ answered by TheSmileyCoder

Yes.

It could go something like this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub tb_PhoneNumber_DoubleClick()
  2.  
  3. 'error checking
  4.   'Check that we have a phonenumber in the textbox
  5.   If Me.tb_PhoneNumber & "" ="" then
  6.     MsgBox "No phonenumber entered"
  7.     Exit Sub
  8.   End If
  9.  
  10.   'Check that frm_EnterOrder is open
  11.   If Not Currentproject.AllForms("frm_EnterOrder").IsLoaded Then
  12.     'Form is not open, so cannot transfer to form, simply exit
  13.     Exit Sub
  14.   End If
  15.  
  16.   'Ask user if he wishes to transfer phonenumber
  17.     if vbyes=Msgbox("Do you wish to transfer phonenumber: " & me.tb_PhoneNumber & " to your current order?",vbyesno,"Transfer phonenumber?") Then
  18.      Forms("frm_EnterOrder").tb_PhoneNumber=Me.tb_PhoneNumber
  19.    End If
  20. 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?

4 2057
TheSmileyCoder
2,321 Expert Mod 2GB
Yes.

It could go something like this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub tb_PhoneNumber_DoubleClick()
  2.  
  3. 'error checking
  4.   'Check that we have a phonenumber in the textbox
  5.   If Me.tb_PhoneNumber & "" ="" then
  6.     MsgBox "No phonenumber entered"
  7.     Exit Sub
  8.   End If
  9.  
  10.   'Check that frm_EnterOrder is open
  11.   If Not Currentproject.AllForms("frm_EnterOrder").IsLoaded Then
  12.     'Form is not open, so cannot transfer to form, simply exit
  13.     Exit Sub
  14.   End If
  15.  
  16.   'Ask user if he wishes to transfer phonenumber
  17.     if vbyes=Msgbox("Do you wish to transfer phonenumber: " & me.tb_PhoneNumber & " to your current order?",vbyesno,"Transfer phonenumber?") Then
  18.      Forms("frm_EnterOrder").tb_PhoneNumber=Me.tb_PhoneNumber
  19.    End If
  20. 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?
Jan 24 '11 #2
araman
53
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.navigationsubform for it to work

Thanks
Jan 24 '11 #3
TheSmileyCoder
2,321 Expert Mod 2GB
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 NameOfControlContaingingSubForm with the name of the control containing your frm_EnterOrder.
Expand|Select|Wrap|Line Numbers
  1. 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.
Feb 28 '11 #4
araman
53
Thanks, I figured it out in short order right after the post
Feb 28 '11 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Chris Nighswonger | last post: by
3 posts views Thread by David C. Allen | last post: by
9 posts views Thread by Vinodh Kumar P | last post: by
11 posts views Thread by typingcat | last post: by
4 posts views Thread by Andrea De Santi | last post: by
4 posts views Thread by Peter Afonin | last post: by
7 posts views Thread by Boki | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.