Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / May 2008

Tip: Looking for answers? Try searching our database.

add data from text box to record with button

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steve - 29 May 2008 14:31 GMT
I am having a little trouble figuring out the code to put in to just simply
add information I have entered in 3 or 4 text box fields to a table I have in
access.

Basically it's like this, I have 4 text boxes (date, forman, notes and
quantity) and when I click a button I want it to add those 4 entries into a
table.

But I can't for the life of me figure out the code. can anybody help?
PJFry - 29 May 2008 15:06 GMT
Steve,

Is there a reason you are not using a bound control for the data entry?  

I am assuming that the table you want to write this data to already has the
four fields.

PJ

> I am having a little trouble figuring out the code to put in to just simply
> add information I have entered in 3 or 4 text box fields to a table I have in
[quoted text clipped - 5 lines]
>
> But I can't for the life of me figure out the code. can anybody help?
Steve - 29 May 2008 15:18 GMT
Basically I have 2 tables already set up. One has multiple columns, but
between the two tables they hvae a relation for the item #. Now what i'm
basically trying to do is add text box's to the form  that will allow me to
add to the 2nd table I have stored.

So basically it's set like this. I have item # 10 in view. Showing me all of
the information from the primary table. item #... cost.. discription..
quantity.. so on and so forth. Now below this I had added the 4 text boxes to
enter information that would relate to the 2nd table.  I would like to just
set it so i could click the update button so it would add the information I
had added into the text fields, and add it to the 2nd table I have stored.

I'm guessing it is related to the .addNew function but I can't figure out
the coding.

The table is named "Work Done" and the fields are Item no, Date, Foreman,
Notes and Qty.

I have these text boxes in a form that has the first table's information
listed in bound text boxes already.

> Steve,
>
[quoted text clipped - 14 lines]
> >
> > But I can't for the life of me figure out the code. can anybody help?
PJFry - 29 May 2008 15:57 GMT
What you need is a subform for those four values.  

Create a form that only contains the elements that you are trying to update
on your second table.  Make sure you include the field the relationship is
based on.  

In your toolbox on the first form, use the Add Subform/Subreport button and
select where you want your subform to go.  The wizard will ask how you want
to relate the two forms.  Select the field that you use to relate them and
you should be good to go.

Give that a try and let me know if you run into any problems.

PJ

> Basically I have 2 tables already set up. One has multiple columns, but
> between the two tables they hvae a relation for the item #. Now what i'm
[quoted text clipped - 35 lines]
> > >
> > > But I can't for the life of me figure out the code. can anybody help?
Steve - 29 May 2008 16:13 GMT
Actually I've already done that on the form :P.

I have my form with all the information listed from table1 and a subform
below that with table2. Thing is, instead of entering information in the
subform, I would like to have the information able to be entered and when I
click the button i created, it save that information by adding it to table2.
table1 is really just for show, table 2 has information thta will be added.
Basically i'm looking for the code i could put to save the information
entered in particular text boxes and save it to table2.

> What you need is a subform for those four values.  
>
[quoted text clipped - 50 lines]
> > > >
> > > > But I can't for the life of me figure out the code. can anybody help?
PJFry - 29 May 2008 16:40 GMT
Fair enough.  

It sounds like the text boxes are on the main form, the values they control
are on the subform.  Assuming that is correct...

First, you want your text boxes to be unbound controls, if they are not
already.  Then on the OnClick event for your button, put the following code:

Forms![Main Form Name]![Subform Name]![Name of first value on subform] =
Me.[Name of first value on main form]

Just replace the names here with the actual form names.  

From the description I still think you should be entering the values
directly into the subform, but this should do the trick.  Let me know if it
does not work.

PJ

> Actually I've already done that on the form :P.
>
[quoted text clipped - 60 lines]
> > > > >
> > > > > But I can't for the life of me figure out the code. can anybody help?
Steve - 29 May 2008 16:50 GMT
That actually worked perfectly JP. The only thing is that it replaces the
first entry on my subform instead of adding it as "new". I'm going to search
a little more to prevent this but i'm sure you have it on the tip of your
tongue.

> Fair enough.  
>
[quoted text clipped - 79 lines]
> > > > > >
> > > > > > But I can't for the life of me figure out the code. can anybody help?
Steve - 29 May 2008 18:31 GMT
I figured out how to add it as new.
Basically like this..

       'add record to sub form
       Me![Work Done Subform].SetFocus
       DoCmd.GoToRecord , , acNewRec
       
       'assign a value to a field in that sub form
   Forms![Item List]![Work Done Subform]![Date] = Me.[Date]
   Forms![Item List]![Work Done Subform]![Foreman] = Me.[Foreman]
   Forms![Item List]![Work Done Subform]![Notes] = Me.[Notes]
   Forms![Item List]![Work Done Subform]![Qty] = Me.[Qty]
   
       'save the record
       DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

      ' Requery the sub form
       Me![Work Done Subform].Requery

   Me.[Foreman].Value = Null
   Me.[Notes].Value = Null
   Me.[Qty].Value = Null

Only thing now that I want to add is to have an if then else statement to
prevent anything from being added if no value is entered (mainly for adding a
blank entry).
PJFry - 29 May 2008 19:32 GMT
Very good.  You can set the if statement to check the values and you are all
set.  You may wish to have a message box indicating that there is a missing
value.  

> I figured out how to add it as new.
> Basically like this..
[quoted text clipped - 22 lines]
> prevent anything from being added if no value is entered (mainly for adding a
> blank entry).
Steve - 29 May 2008 19:36 GMT
Done and done. Did it all before you even got back to me on that last one.

Again thanks a ton, everything stores and updates perfect now.

Will it always add the item to the begining of the subform or is there a way
to add it to the end of that list?  Guess that'll be my last question before
I retire :P
PJFry - 30 May 2008 03:59 GMT
I am not sure what you mean by the beginning of the subform.  If it is a
continuous form it would always add records after the last one.  Is that what
you mean?

> Done and done. Did it all before you even got back to me on that last one.
>
[quoted text clipped - 3 lines]
> to add it to the end of that list?  Guess that'll be my last question before
> I retire :P
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.