473,396 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Pushing form fields to table

164 100+
Perhaps this is a no brainer...I have a database that is comprised of just one form and one table. This was made quite a while ago for someone, and now they want to do some more with it.

Now they want to have a separate table that holds some of the same information as the original. There are a ton of records in here, and what I was wondering is if there was a button I could put on the form for, whichever record they were on while browsing the form they could hit the button and would send certain (pre defined fields) from that record over to another table.

Reason being: the form right now has all their current customers.. the new form they want is to add new customers in a different way as well as adding SOME of the customers from the original form.. So I thought I would give them the control of who they want to add to the new table by adding this button.

So what I am wondering is how to put the button on there to pass certain fields to a given table.

I do hope this makes sense. I am trying my hardest to get the words to come
out correctly. I would be happy to elaborate!



Thanks in advance!
Jan 22 '08 #1
3 2986
PianoMan64
374 Expert 256MB
yes, that is very easy and it is very possible.

the way that you would do it, is simply open the other table up using VBA code and then when you push the button on the current record, it will copy those select fields over to the new table.

Step 1.

Create a button with the label "Copy Customer" with the controlName called CopyCustomer

Step 2.

scroll down the properties list of the button control until you see the On Click event.

click on the ... and select Code Builder.

Step 3.

Copy and paste the following code for the button.

Expand|Select|Wrap|Line Numbers
  1.  
  2.        Dim MyDB As DAO.Database
  3.        Dim MyRS As DAO.Recordset
  4.  
  5.        Set MyDB = CurrentDb()
  6.        Set MyRS = MyDB.OpenRecordset("SELECT * FROM [TABLENAME]", dbOpenDynaset)
  7.  
  8.         With MyRS
  9.  
  10.                .AddNew
  11.                !FieldNameInTable = Me.ControlNameOnForm.Value
  12.                .Update
  13.         End With
  14.         MyRS.Close
  15.         MyDB.Close
  16.         Set MyRS = Nothing
  17.         Set MyDB = Nothing
  18.  
  19.  
Please NOTE that [TABLENAME] needs to be replaced with the accual table name that the data will be pushed too. also you will need to add the names of the fields in the table and reference the controls on the form. please note the syntax of !fieldname ----- and the control name of me.ControlName.value this will read the value of the controlname on the form.

If you have any questions, please feel free to email me at me@joepottschmidt.com

Hope that helps,

Joe P.
Jan 22 '08 #2
mbatestblrock
164 100+
yes, that is very easy and it is very possible.

the way that you would do it, is simply open the other table up using VBA code and then when you push the button on the current record, it will copy those select fields over to the new table.

Step 1.

Create a button with the label "Copy Customer" with the controlName called CopyCustomer

Step 2.

scroll down the properties list of the button control until you see the On Click event.

click on the ... and select Code Builder.

Step 3.

Copy and paste the following code for the button.

Expand|Select|Wrap|Line Numbers
  1.  
  2.        Dim MyDB As DAO.Database
  3.        Dim MyRS As DAO.Recordset
  4.  
  5.        Set MyDB = CurrentDb()
  6.        Set MyRS = MyDB.OpenRecordset("SELECT * FROM [TABLENAME]", dbOpenDynaset)
  7.  
  8.         With MyRS
  9.  
  10.                .AddNew
  11.                !FieldNameInTable = Me.ControlNameOnForm.Value
  12.                .Update
  13.         End With
  14.         MyRS.Close
  15.         MyDB.Close
  16.         Set MyRS = Nothing
  17.         Set MyDB = Nothing
  18.  
  19.  
Please NOTE that [TABLENAME] needs to be replaced with the accual table name that the data will be pushed too. also you will need to add the names of the fields in the table and reference the controls on the form. please note the syntax of !fieldname ----- and the control name of me.ControlName.value this will read the value of the controlname on the form.

If you have any questions, please feel free to email me at me@joepottschmidt.com

Hope that helps,

Joe P.

Thank you so much! I will be giving this the ole' college try this evening. Again, thanks a ton!
Jan 22 '08 #3
mbatestblrock
164 100+
Thank you so much! I will be giving this the ole' college try this evening. Again, thanks a ton!
Okay, so I got it working.. and I know this may be pushing it but here is my dilemma.. I was hoping someone may have a solution for me. the form that this button is on was and still is being used to filling in information and it has a button on it to export everything to a word tmeplate to print out.. Now they want to he database to be used for more stuff,.

the button works fine but here is my problem. the form i have created has a sub form in it.

so main part of form consists of

CustID (auto num) Name, Address.

and the sub form consists of
CustID (pulled from above) Name, (also pulled from above), Date of order, Amount paid, Amount Due.


so when I hit the copy button what i want it to do is push data from that form into

Main form: Name, Address
Sub form: * all fields

So I am running into the problem of only being able to push fields to one table, which I am sure there is a workaround. but the bigger problem I see is this:

In the form with the copy customer button, If the same customer is in there twice I would like the copy procedure to not make a new record but to insert a new record into the sub form. and on the same note, I dont know what to do as far as a situation where there would happen to two customers with the same name??

I think I may be hosed...? and I hope this all made sense to everyone, I am finding it hard to explain.

If it helps at all, the person I am doing this for starts with the form with the copy button on it for entering in any new customers, this is why I am so concerned about getting the copy button to work, just to make it easier for them so they dont have to open up a new form to enter some of the same information they just did (also possibly entering a wrong number here or there)

I dont know if it possible to have something like this happen when the button is clicked:

a window pop up and have the option to select from a list of customers in the new form to append the results to, or to make a new customer?
-that might be a bit complex, and I don't even know if it can be done, but I thought it was worth a shot.


SO, with that being said, if ANYONE has any advice for me... that'd be great!
Jan 27 '08 #4

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

Similar topics

2
by: Nick | last post by:
Loop to create an array from a dynamic form. I'm having trouble with an application, and I'll try to explain it as clearly as possible: 1. I have a form with two fields, say Apples and...
3
by: Mike Whittemore | last post by:
I am trying to convert an HTML table into a list of name-value pairs, one pair per field in the table. I believe my XSLT is correct, but I've tried both Xalan and Saxon, which both fail with...
7
by: Aravind | last post by:
Hi folks. I have 2 forms, frmBorrow and frmHistory frmBorrow has an unbound multi-column combo box (cboMember) and 7 unbound text boxes (MemNo, MemName, MemIC, MemType, CourseFaculty, Borrow,...
0
by: Jason | last post by:
I have a primary form which is used to enter/edit data in a table named Test_Results. On this primary form there is a subform which displays site addresses. This subform is linked to the primary...
1
by: meganrobertson22 | last post by:
hi everybody- what is the best way to add data from one form to another? i have 2 tables: person and contract. here are some of the fields. table: person personid (autonumber and primary...
3
by: Bill | last post by:
I'm using the POST method to submit a simple form html page with yes/no and checkbox fields to an asp response page which stores the values in a new dim string, then uses it to build a new table...
3
by: bronen | last post by:
I need a step by step instruction to do the following (i'm a beginner): 1) I have a form with two unbound text boxes. ProjectNumber, ProjectName 2) I have a form called "GoTeam" with two...
2
by: adwest | last post by:
Forgive me if this is a foolish question. I "play" in Access and have only created a few rather simple relational databases. My knowledge and experience is limited. I have no formal training, just...
3
by: ibeehbk | last post by:
Hi. I have a form made in xhtml. I test via vbscript to make sure none of the fields are empty and properly formatted (ie email). All the regular fields work. However, I have two drop down menus...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.