DataBase - Append Query problem

Asked By Rocky
29-Jan-10 02:05 AM
I have an Append Quey that works fine when you right click on the
query ("ReaderIndCancelProforma_Append") and choose open

INSERT INTO Reader_DistrHistory ( DistrId, [Reader Id], [Date on
mailing list], TypeId, ReasonId, Reason, [Date off mailing list] )
SELECT Reader_DistrCurrent.DistrId, Reader_DistrCurrent.[Reader Id],
Reader_DistrCurrent.[Date on mailing list], 6 AS Type, 15 AS Reas,
[Forms]![Reader_CancelProforma]![Remarks] AS Remark, Now() AS off
FROM Reader_DistrCurrent
WHERE (((Reader_DistrCurrent.[Reader Id])=[Forms]![Reader_DB]![Reader
Id]));

The problem I have is when I run the query from a command button on a
form.  It only appends the [Reader Id]

Private Sub Command8_Click()
On Error GoTo Command8_Click_Err

DoCmd.SetWarnings False

DoCmd.OpenQuery "ReaderIndCancelProforma_Append",
acViewNormal, acEdit 'this doesnt work

DoCmd.OpenQuery
works

DoCmd.OpenQuery "ReaderIndProFormaCancel_Delete",
acViewNormal, acEdit ' this works

DoCmd.OpenQuery "ReaderIndProformaCancel_Update",
acViewNormal, acEdit 'this works


DoCmd.SetWarnings True

Command8_Click_Exit:
Exit Sub

Command8_Click_Err:
MsgBox Error$
Resume Command8_Click_Exit

End Sub

Why should this suddenly happen.  All the other queries work fine

I have other forms that run similar code and they all work fine.

Would appreciate some help on what the problem could be

Rocky Swartz.
OpenQueryDoCmd.OpenQuery
(1)
DoCmd.RunSQL
(1)
ReaderIndCancelProformaHistChange
(1)
DistrCurrent.DistrId
(1)
DoCmd.SetWarnings
(1)
DoCmd.OpenQuery
(1)
ReaderIndProFormaCancel
(1)
ReaderIndCancelProforma
(1)
  Jeanette Cunningham replied to Rocky
29-Jan-10 02:01 AM
When you say it does not work - what actually happens?
You can put in some debugging code to help you find the error.
-----------------
Private Sub Command8_Click()
'On Error GoTo Command8_Click_Err

'DoCmd.SetWarnings False

Debug.Print Forms!Reader_DB!ReaderId
Debug.Print Forms!Reader_CancelProforma!Remarks

DoCmd.OpenQuery "ReaderIndCancelProforma_Append",
acViewNormal, acEdit 'this doesnt work

End Sub
----------------

To debug, put those lines of code in your button click routine, comment out
the error handler and the set warnings statements.
Click the button to run the query.
Open the immediate window Ctl+G to see what access got for ReaderID and
Remarks


If the form Reader_DB is not open when you click the button, the query will not
run because it will not be able to get the value for ReaaderId.
Same thing for the form Reader_CancelProforma
You can also open both forms Reader_DB and Reader_CancelProforma and open a
copy of that query saved as a select query to see what data it picks up from
the 2 forms.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
  Chegu Tom replied to Rocky
29-Jan-10 12:35 PM
Try   DoCmd.RunSQL  instead of OpenQuery


DoCmd.OpenQuery
Create New Account
help
How to enter this DoCmd.RunSQL DataBase I am trying to get access 2003 to accept a final DoCmd.RunSQL at the end of this Private Sub Form_Load() DoCmd.SetWarnings False 'Build the 4 new tables DoCmd.RunSQL "SELECT DISTINCT Lot1 AS Lot INTO LOT1 FROM BATCH DoCmd.RunSQL "SELECT DISTINCT Lot2 AS Lot INTO LOT2 FROM BATCH" DoCmd.RunSQL "SELECT DISTINCT LotC AS
VBA DoCmd.RunSQL DataBase The following statement produces an error that DoCmd.RunSQL requires an argument that is an SQL statement: DoCmd.RunSQL "SELECT * & _ _SCHOOL is the name of my Access table. Why is this not a Xetex Business Systems 610-898-1551 1-800-356-2772 Ext 12 Access Queries Discussions DoCmd.RunSQL (1) VBA (1) OhFg (1) Xetex (1) Ext (1) Semi (1) Is the name _SCHOOL
DoCmd RunSQL parameters DataBase From the statement below, var is not recognized when DoCmd RunSQL is executed. What's wrong with it ? Dim SQL, var As String var = Form!Test Test!testvar2 & Form!Test!Testvar3 SQL = "INSERT INTO TABLENAME VALUES(Forms!Test!name, var)" In DoCmd.RunSQL Thanks in advance Access Modules DAO Discussions DoCmd.RunSQL (1) CurrentProject.Connection.Execute (1) Accounting (1) VBA (1) Currentdb.Execute (1) PastedSQL (1) AdCmdText
DoCmd.RunSQL woes with update query DataBase Hi I am trying to get the following to work but with little success tempsql = Me.Combo26.Value & Me.Area & Me.Text35 & "NP" DoCmd.RunSQL ("UPDATE WSLevs SET [WSLevs].[NodePointName] = " & tempsql & "[WSLevs]. [WaterCourseRef] & Replace([WSLevs].[Reference], ""."", """");") If I just try DoCmd.RunSQL ("UPDATE WSLevs SET [WSLevs].[NodePointName] = [WSLevs]. [WaterCourseRef] & Replace([WSLevs].[Reference], ""."", """");") The command works. With the correct syntax for the first query please? Thanks. Nick Access Queries Discussions WSLevs.NodePointName (1) DoCmd.RunSQL (1) ExpectedDoCmd.RunSQL (1) DoCmd.OpenQuery (1) StringstrSQL (1) Debug.Print (1) WaterCourseRef (1) NodePointName
DoCmd.RunSQL "UPDATE tblDatabase DataBase Dim varReturn As Variant varReturn = DLookup("[User1]", "tblDatabase", "[UID] = " & Me.UID) If IsNull(varReturn) Then DoCmd.RunSQL "UPDATE tblDatabase SET User1 = '" & [TempVars]![varUser] & "'" End If The following command line is updating me record. How can I do to just modify the current record? Access Modules DAO Discussions DoCmd.RunSQL (1) Debug.Print (1) SomeIDField (1) VariantvarReturn (1) SomeCriteria (1) TempVars (1) NumField (1) VarUtilizator Dim varReturn As Variant varReturn = DLookup("[User1]", "tblDatabase", "[UID] = " & Me.UID) If IsNull(varReturn) Then DoCmd.RunSQL "UPDATE tblDatabase SET User1 = '" & [TempVars]![varUtilizator] & "' WHERE UID = ' " & Me.UID & " ' " or even DoCmd.RunSQL "UPDATE