|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
hello
how can i change a row's data from a form that have no relationships with that table? thanks |
|
#2
|
||||
|
||||
|
Quote:
__________________
Experience is the thing you have left when everything else is gone. |
|
#3
|
|||
|
|||
|
and what's that event procedure?
|
|
#4
|
|||
|
|||
|
Use a button Click or form Close or box Update event with code like:
DoCmd.RunSQL "UPDATE tablename SET fieldname ='" & name of variable or box here & "' WHERE fieldname = '" & some value here probably from a variable or box or recordset field & "'" The apostrophes are needed if field is text, # symbol if field is date and nothing if field is numeric. Note how the variables are concatenated, if you use literals don't concatenate, just include within the quotes but delimiter rules still apply. Attempt code, post for analysis if you encounter problem. Last edited by June7 : October 22nd, 2009 at 01:20 PM. |
|
#5
|
|||
|
|||
|
...
i am a bit new to access and i dont know SQL... by the way i don't undrestand this thing that you wrote in code: "some value here probably from a variable or box or recordset field" ... i want to change data on the "customers" tabel at the field "index" to a certain row that is on "rowcode" variable ,it's a number and insert "f$" to it. can you change the code to this mode? .... DoCmd.RunSQL "UPDATE customers SET customers.index ='" & F$ & "' WHERE customers.index= '" & i dont know what to insert & "'" Last edited by sepehr : October 22nd, 2009 at 01:53 PM. Reason: wrong word |
|
#6
|
|||
|
|||
|
If you don't give the SQL command criteria in the WHERE clause, every record will be updated. So you need to 'capture' the criteria somehow. Possibly by reference to fields of the record the form is open to or by having user enter value into a textbox or determined somehow in code.
Tell me more about this 'index' field. What is it for? The example you show would find every record with a particular index value and replace that value. You mention a variable 'rowcode'. How is its value set? Would it be a value in a field in the table? Suggest you look at some SQL tutorials. There are lots available on the net. Here's one for starters http://www.sql-tutorial.net/ Last edited by June7 : October 23rd, 2009 at 01:04 PM. |
|
#7
|
|||
|
|||
.... so my code will be: for rowcode = 0 to txtnumber - 1 f$ = SOME CALCULATIONS DoCmd.RunSQL "UPDATE customers SET customers.index ='" & F$ & "' WHERE customers.ID= '" & rowcode + 1 & "'" next rowcode ... but "Data type mismatch in criteria expression." Error will appear. the thing in f$ will be a 3 digit number but like as this :"018" i dont want to be converted to 18 instead of "018"... |
|
#8
|
|||
|
|||
just converted "rowcode" to a string and it works: DoCmd.RunSQL "UPDATE customers SET customers.index ='" & F$ & "' WHERE customers.ID= '" & mid$(rowcode + 1,1) & "'" ... ![]() ... can i disable that confirmation?, because my operation will not effect any user's data, it's just sending (and saving) information to another form |
|
#9
|
|||
|
|||
|
Code:
DoCmd.SetWarnings False DoCmd.RunSQL "UPDATE customers SET customers.index ='" & F$ & "' WHERE customers.ID= '" & mid$(rowcode + 1,1) & "'" DoCmd.SetWarnings True Quote:
|
|
#10
|
||||
|
||||
|
thanks a lot for your help,
Quote:
I'm just using it to save that data to be read by another form, its one of the user settings. |
|
#11
|
|||
|
|||
|
That is one way to make the value available but it isn't necessary to save a value to a table in order to pass to another form. If you have no other purpose for the value you can use the OpenArgs argument of the DoCmd.OpenForm command if the form is to be opened by the form that captures the value. If you need the value later then could use a global variable.
|
|
#12
|
|||
|
|||
|
sepehr,
What point do you disagree with? Perhaps I could clarify. I routinely pass values to a form or report without saving to a table. I am not saying that is the best approach for your situation but it is an option. |
|
#13
|
|||
|
|||
oh sorry ,i was exploring site places ,just wanted to see what will happen... . |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft Access Help > Reports - Change data in a tabel |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|