473,383 Members | 1,872 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,383 software developers and data experts.

how to update table

553 512MB
I have a text field on a Form, which is linked with table.

If i input some value in the text field, how would i update the table with the inputted value - without closing the form ?

I have tried using Me.Requery but it dosn't append the new value to the old ones but replaces the old value.

Any help?
Jul 19 '07 #1
9 2095
vkong85
24
you can run the textbox off a append query so everytime you requery it appends it onto the table.
Jul 19 '07 #2
questionit
553 512MB
Can you tell me how to do it?


you can run the textbox off a append query so everytime you requery it appends it onto the table.
Jul 19 '07 #3
missinglinq
3,532 Expert 2GB
There's no need to run an append query for this simple task! You just need to Save the record for it to be written to your table. Assuming that all required fields have data, if you move to another record, the record will be Saved. If you close the form, the record will be Saved! You should always get a warning if you move to another record or go to close the form if any required fields are empty, but this doesn't always happen when you go to close the form! Sometimes Access simply dumps the incomplete record, without any warning! You can also, at any time, explicitly Save the record, either with

Docmd.RunCommand acCmdSaveRecord

or with:

If Me.Dirty Then Me.Dirty = False

Linq ;0)>
Jul 19 '07 #4
questionit
553 512MB
Linq,

Both the methods you have told me does not append new values to record. It still replaces the old value.

How would you add new record to the table?


There's no need to run an append query for this simple task! You just need to Save the record for it to be written to your table. Assuming that all required fields have data, if you move to another record, the record will be Saved. If you close the form, the record will be Saved! You should always get a warning if you move to another record or go to close the form if any required fields are empty, but this doesn't always happen when you go to close the form! Sometimes Access simply dumps the incomplete record, without any warning! You can also, at any time, explicitly Save the record, either with

Docmd.RunCommand acCmdSaveRecord

or with:

If Me.Dirty Then Me.Dirty = False

Linq ;0)>
Jul 19 '07 #5
hyperpau
184 Expert 100+
Linq,

Both the methods you have told me does not append new values to record. It still replaces the old value.

How would you add new record to the table?

The confusion is here is caused by your use of the "Append" word.
when you say append, we normally understand it as replacing the old value.
So if I understand it correctly, you want to add a new value in the combo box right? meaning, the old value will stay unchanged, and the new value becomes a new choice in the list?

you just need to requery. But requery only that field and not the whole form.

this are my suggestions.

That combo box field you have there, format it as limit to list = Yes
so that if a user types a new data which is not yet in the list, they would not be able to change or append that old value currently selected.

then create an unboun form where a user can add a new value to the list.

details:

(assuming your combo box is bound to a table that contains the choices in the combobox)

add an 'On DblClick' and 'On Not in List' event procedure to that combo box field.
let's say your combo box field is named [comboDescription]
add a vba code to the OnNotinList event.

Expand|Select|Wrap|Line Numbers
  1. Private Sub comboDescription_NotInList(NewData As String, Response As Integer)
  2.     MsgBox "Text you entered is not in the List" & _
  3.             vbCrLf & "Double Click to Add a new Descripton.", , "Error!"
  4.     Response = DataErrCont
  5. End Sub
when a user types in a new value in the combo box which is not yet on the list of choices (not yet in the table where the combo box is bound to), then
access would prompt the user saying that what they typed in is not in the list.
Then that message box would also tell them that to add that value, they must
double click the combo box.

Now, you create an unbound form to let the user add a new description in the combobox.

This unbound form would have a textbox bound to the descriptions table, then two command buttons. one for add/save, and one for cancel.
Have this unbound form's property set to Date Entry = Yes

Then the 1st command button, let's say an "Add" button should command
access to save whatever the user types in the text box to the table of the descriptions.

So the OnClick event procedure of the add button is something like this:

(Let's say the orginal form is named "frmProducts" and the unbound form is named "frmAddDescription")

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdAdd_Click()
  2.     If IsNull(Me![Description]) Then
  3.         MsgBox "There is no Description to Add." & _
  4.         vbCrLf & "Please click Cancel to Close the Form.", _
  5.         vbInformation, "Add a Description"
  6.     Else
  7.     DoCmd.RunCommand acCmdSaveRecord
  8.     DoCmd.Close acForm, "frmAddDescription", acSaveYes
  9.     Forms![frmProducts]![comboDescription].Requery
  10.     End If
  11. End Sub
The other button in the unbound form is the cancel button that just closes
the unbound form. you may use the wizard for this.


Now lets go back to the original form "frmProducts".
After adding that NotInList event.
we will now add the "On Dbl Click" event.

Expand|Select|Wrap|Line Numbers
  1. Private Sub comboDescription_DblClick(Cancel As Integer)
  2.     Me![comboDescription] = ""
  3.     DoCmd.OpenForm "frmDescription"
  4. End Sub
There you go, your issue is resolved. The scenario would be like this.

The user opens your form 'frmProducts' then input information, now
the user needs to select a description of the product from the combobox
'comboDescription'.
Unfortunately, the combo box does not have the description the user is looking for for this product. therefore he types a new one in the combobox.
since the description he typed is not in the list, a message box appears
saying "Text you entered is not in the list. Double click to add a new description"


so the user clicks ok on the message box then of course, follows what the message box said. The user double clicks the combo box.

This would open the unbound form 'frmAddDescription' without closing the current form.

now on the unbound form, the user types that new description in the text box and clicks the "Add" button.
this closes the unbound form and the focus goes back to the original form.
When the user click the down arrow of the combo box, he will now see the
new description he entered in the unbound form and selects that. :)

Hope this would help.
Jul 19 '07 #6
missinglinq
3,532 Expert 2GB
hyperpau
So if I understand it correctly, you want to add a new value in the combo box right?
Where in this post is a combobox ever mentioned?

questionitHow would you add new record to the table?
To add a new record to a table you have to first move to a new record then enter your data. It now sounds like you're trying to enter data in an existing record and then expect it to be saved to a new record!

To go to a new record either

Click on the far right button in the records navigation box (the one with an asterisk next to it or place a button on your form with this code behind it:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.GoToRecord , , acNewRec
  2.  
.
Jul 19 '07 #7
questionit
553 512MB
Thanks a lot for your details help.

but what i was asking was the method to save a value in a table.

I have a TextBox, i type any value in it. This value should store in already existing table that has been linked with the Text Field.

There are already some values in the table, so the new value should tore in the end (by adding a new row)

how would i do that..... i know when we do Me.Requery kind of things, the new value gets stored in table - but this way the old and the most reent value gets replaced - but i want to add a new row?


The confusion is here is caused by your use of the "Append" word.
when you say append, we normally understand it as replacing the old value.
So if I understand it correctly, you want to add a new value in the combo box right? meaning, the old value will stay unchanged, and the new value becomes a new choice in the list?

you just need to requery. But requery only that field and not the whole form.

this are my suggestions.

That combo box field you have there, format it as limit to list = Yes
so that if a user types a new data which is not yet in the list, they would not be able to change or append that old value currently selected.

then create an unboun form where a user can add a new value to the list.

details:

(assuming your combo box is bound to a table that contains the choices in the combobox)

add an 'On DblClick' and 'On Not in List' event procedure to that combo box field.
let's say your combo box field is named [comboDescription]
add a vba code to the OnNotinList event.

Expand|Select|Wrap|Line Numbers
  1. Private Sub comboDescription_NotInList(NewData As String, Response As Integer)
  2.     MsgBox "Text you entered is not in the List" & _
  3.             vbCrLf & "Double Click to Add a new Descripton.", , "Error!"
  4.     Response = DataErrCont
  5. End Sub
when a user types in a new value in the combo box which is not yet on the list of choices (not yet in the table where the combo box is bound to), then
access would prompt the user saying that what they typed in is not in the list.
Then that message box would also tell them that to add that value, they must
double click the combo box.

Now, you create an unbound form to let the user add a new description in the combobox.

This unbound form would have a textbox bound to the descriptions table, then two command buttons. one for add/save, and one for cancel.
Have this unbound form's property set to Date Entry = Yes

Then the 1st command button, let's say an "Add" button should command
access to save whatever the user types in the text box to the table of the descriptions.

So the OnClick event procedure of the add button is something like this:

(Let's say the orginal form is named "frmProducts" and the unbound form is named "frmAddDescription")

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdAdd_Click()
  2.     If IsNull(Me![Description]) Then
  3.         MsgBox "There is no Description to Add." & _
  4.         vbCrLf & "Please click Cancel to Close the Form.", _
  5.         vbInformation, "Add a Description"
  6.     Else
  7.     DoCmd.RunCommand acCmdSaveRecord
  8.     DoCmd.Close acForm, "frmAddDescription", acSaveYes
  9.     Forms![frmProducts]![comboDescription].Requery
  10.     End If
  11. End Sub
The other button in the unbound form is the cancel button that just closes
the unbound form. you may use the wizard for this.


Now lets go back to the original form "frmProducts".
After adding that NotInList event.
we will now add the "On Dbl Click" event.

Expand|Select|Wrap|Line Numbers
  1. Private Sub comboDescription_DblClick(Cancel As Integer)
  2.     Me![comboDescription] = ""
  3.     DoCmd.OpenForm "frmDescription"
  4. End Sub
There you go, your issue is resolved. The scenario would be like this.

The user opens your form 'frmProducts' then input information, now
the user needs to select a description of the product from the combobox
'comboDescription'.
Unfortunately, the combo box does not have the description the user is looking for for this product. therefore he types a new one in the combobox.
since the description he typed is not in the list, a message box appears
saying "Text you entered is not in the list. Double click to add a new description"


so the user clicks ok on the message box then of course, follows what the message box said. The user double clicks the combo box.

This would open the unbound form 'frmAddDescription' without closing the current form.

now on the unbound form, the user types that new description in the text box and clicks the "Add" button.
this closes the unbound form and the focus goes back to the original form.
When the user click the down arrow of the combo box, he will now see the
new description he entered in the unbound form and selects that. :)

Hope this would help.
Jul 20 '07 #8
missinglinq
3,532 Expert 2GB
Post # 7 explains how to do this! You have to go to a new record first, then enter data in your text field! Then save it to your table! You cannot enter data into a text box on an existing record and expect it to be appended to the table as a new record!
Jul 20 '07 #9
hyperpau
184 Expert 100+
Thanks a lot for your details help.

but what i was asking was the method to save a value in a table.

I have a TextBox, i type any value in it. This value should store in already existing table that has been linked with the Text Field.

There are already some values in the table, so the new value should tore in the end (by adding a new row)

how would i do that..... i know when we do Me.Requery kind of things, the new value gets stored in table - but this way the old and the most reent value gets replaced - but i want to add a new row?
That answers your question. If you just want to add a new data in the table where the text box is bound, but not enter a whole new record, then you have to change your textbox to a combo box. On the design view, right click the text box and change it to combo box.

But if what you're talking about is to add a whole new record with that new value for the textbox, thene missinling gave you the answer already.
Jul 20 '07 #10

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

Similar topics

7
by: Dave | last post by:
I have 2 tables, one with names, and another with addresses, joined by their CIVICID number (unique to the ADDRESSINFO table) in Oracle. I need to update a field in the NAMEINFO table for a...
8
by: Lauren Quantrell | last post by:
In VBA, I constructed the following to update all records in tblmyTable with each records in tblmyTableTEMP having the same UniqueID: UPDATE tblMyTable RIGHT JOIN tblMyTableTEMP ON...
17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
2
by: Mike Leahy | last post by:
Hello all, This question is related to updating tables - is there any way to calculate or update the values in a column in a table to the values in a field produced by a query result? An...
16
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that there is a threshold on the number of columns of the...
5
by: PAUL | last post by:
Hello, I have 2 tables with a relationship set up in the dataset with vb ..net. I add a new record to the parent table then edit an existing child record to have the new parent ID. However when I...
2
by: Miro | last post by:
I will ask the question first then fumble thru trying to explain myself so i dont waste too much of your time. Question / Statement - Every mdb table needs a PrimaryKey ( or maybe an index - i...
1
by: adithi | last post by:
My Table Structure is: Table A Table B Table C colA -PK Col B-PK Col C-PK Col B-FK ...
3
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.