Hi Marco,
after you make changes to a table using SQL, you need to refresh the
table definitions so that other processes (ie: your form) sees the changes
currentdb.tabledefs.refresh
DoEvents
*** DoEvents ***
DoEvents is used to make VBA pay attention to what is currently
happening and look to see if the OS (Operating System) has any requests.
ie: if you have a loop and want to be able to BREAK it with CTRL-BREAK,
put DoEvents into the loop
DoEvents will also update values written to a form by a general
procedure or code behind another form or report
A DoEvents is done when you use MsgBox, or are stepping through code
(since it has to pay attention to the keyboard)
It is a good way to say, "Wake Up!"
***
before you update your table using SQL, you should save changes to the
form...
if me.dirty then me.dirty = false
***
since you are using CurrentDb.Execute,
you don't need
DoCmd.SetWarnings False
***
it is also a good idea to assign the SQL to a string so that you can
examine it -- you also need # delimiters around the date to compare
you also need to qualify field1 with qryname.field1 so Access knows
where it comes from (field1 is in both tables and Access needs to know
which to get it from)
~~~~~~~~~~~~~~~~~
Dim strSql As String
'create SQL to update records
strSql = ""UPDATE tblname " _
& " INNER JOIN qryname " _
& " ON tblname.ID = qryname.ID " _
& " SET tblname.field1 = qryname.[field1]" _
& " , tblname.field2 = qryname.[field2]" _
& " , tblname.field3 = qryname.[field3] " _
& " WHERE tblname.aDate >= #" & Date()-50 & "#;"
'comment this out after debugged
'Debug.Print strSql
'run the SQL statement
CurrentDb.Execute strSql
'refresh the table definitions with records
'added/modified by other persons/processes
CurrentDb.TableDefs.Refresh
'wake-up call for Access
DoEvents
'----------------- keep and customize what is relevant
'requery a subform
Me.subform_controlname.Requery
'requery the form you are behind
Me.FrmSubItinerary2.Requery
'-----------------
~~~~~~~~~~~~~~~~~~~````
** debug.print ***
debug.print strSQL
--> this prints a copy of the SQL statement to the debug window (CTRL-G)
After you execute your code, open the Debug window
CTRL-G to Goto the debuG window -- look at the SQL statement
If the SQL statement has an error
1. Make a new query (design view)
2. choose View, SQL from the menu
(or SQL from the toolbar, first icon)
3. cut the SQL statement from the debug window
(select, CTRL-X)
4. paste into the SQL window of the Query
(CTRL-V)
5. run ! from the SQL window
-- Access will tell you where the problem is in the SQL
'~~~~~~~~~~~~~~
"in qryname the field1-3 are calculated field"
what kind of calculation? If it uses dSum, dCount, or another domain
aggregate function, this won't work...
Warm Regards,
Crystal
*

have an awesome day

*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
Hi strive4peace,
"doesn 't show new values"
perhaps no records meet the criteria...
WHERE (((tblname.aDate)>=Date()-50))
I have new values in qryname and I have cancelled some in the table. ;-)
I have tried also in the command button
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdRefresh
CurrentDb.Execute ("UPDATE tblname INNER JOIN qryname ON tblname.ID =
qryname.ID SET tblname.field1 = [field1], tblname.field2 = [field2],
tblname.field3 = [field3] WHERE tblname.aDate >=Date()-50")
DoCmd.SetWarnings True
"it doesn 't work as it would have"
what do you mean by this?
If i switch in access 2003 works well:
1) the update query
2) the command button
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdRefresh
DoCmd.OpenQuery "qryname", acViewNormal, acEdit
DoCmd.SetWarnings True
3) the command button2
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdRefresh
CurrentDb.Execute ("UPDATE tblname INNER JOIN qryname ON tblname.ID =
qryname.ID SET tblname.field1 = [field1], tblname.field2 = [field2],
tblname.field3 = [field3] WHERE tblname.aDate >=Date()-50")
DoCmd.SetWarnings True
4) the update query design view, datasheet view
Is it a bug ?
Note:
beta2tr
in qryname the field1-3 are calculated field
Regards
Warm Regards,
Crystal
*

have an awesome day

*
Also to You
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
Marco wrote:
In access 2003 I use a update query for update a table.
This works perfectly:
UPDATE tblname INNER JOIN qryname ON tblname.ID = qryname.ID SET
tblname.field1 = [field1], tblname.field2 = [field2], tblname.field3 =
[field3]
WHERE (((tblname.aDate)>=Date()-50));
In access 2007 doesn 't show new values and it doesn 't work as it would
have. Why?
thx