Originally Posted by
pbaldy
Not how you're using it. A DLookup() within a query field could be horribly slow, but a single one to get a value to be used later should be quite fast.
Hey Pbaldy,
Only got a few minutes to try some things out today, but kept returning the error: " Can not insert data with action query"
Code:
Dim strSQLQ As String
Dim strACNMBR As String
DoCmd.RunSQL "DELETE * FROM AllData"
DoCmd.RunSQL "DELETE * FROM SummaryType1"
DoCmd.RunSQL "DELETE * FROM SummaryType2"
'AllData is the main table where the append query is sending the data
'SummaryType1 & SummaryType2 are tables being populated based on queries summarized types of data stored in the table: AllData
strACNMBR = DLookup("ACCOUNTS", "AccountsForForms")
strSQLQ = "INSERT INTO MyAppendQuery (AC_NR) SELECT [MyLinkedTable]![AC_NR] FROM [MyLinkedTable] WHERE ([MyLinkedTable]![AC_NR]= " & "'" & strACNMBR & "'" & ")"
DoCmd.RunSQL strSQLQ
DoCmd.OpenQuery "MyAppendQuery"
Beep
DoCmd.OpenQuery "SummaryType1Query"
DoCmd.OpenQuery "SummaryType2Query"
Beep
[Forms]![DataSelection]![Type1SummarizedData].Requery
[Forms]![DataSelection]![Type2SummarizedData].Requery
Beep
MsgBox "Process Finished ", vbInformation
End Sub
I also went back to the QueryDef approach, and got it to run slightly, but not the intended results. It turned my append query into a select query based on the where criteria. It's not updating the query I'm referencing in the set qdf function. Am I supposed the SQL for the quer that I'm trying to update the criteria?
Is it possible, that I'm not stating the parameters, so it changes the entire query to match the "where" statement?
Code:
Dim strSQLQ As String
Dim strACNMBR As String
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
DoCmd.RunSQL "DELETE * FROM AllData"
DoCmd.RunSQL "DELETE * FROM SummaryType1"
DoCmd.RunSQL "DELETE * FROM SummaryType2"
Set db = Application.CurrentDb
Set qdf = db.QueryDefs("MyAppendQuery")
strACNMBR = DLookup("ACCOUNTS", "AccountsForForms")
strSQLQ = "SELECT [MyLinkedTable]![AC_NR] FROM [MyLinkedTable] WHERE ([MyLinkedTable]![AC_NR]= " & "'" & strACNMBR & "'" & ")"
qdf.Sql = strSQLQ
DoCmd.OpenQuery "MyAppendQuery"
Beep
DoCmd.OpenQuery "SummaryType1Query"
DoCmd.OpenQuery "SummaryType2Query"
Beep
[Forms]![DataSelection]![Type1SummarizedData].Requery
[Forms]![DataSelection]![Type1SummarizedData].Requery
Beep
MsgBox "Process Finished ", vbInformation
End Sub
If I change the above from a SELECT into an INSERT INTO, I get a syntax error on the highlighted section.
Code:
Code:
Dim strSQLQ As String
Dim strACNMBR As String
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
DoCmd.RunSQL "DELETE * FROM AllData"
DoCmd.RunSQL "DELETE * FROM SummaryType1"
DoCmd.RunSQL "DELETE * FROM SummaryType2"
Set db = Application.CurrentDb
Set qdf = db.QueryDefs("MyAppendQuery")
strACNMBR = DLookup("ACCOUNTS", "AccountsForForms")
strSQLQ = "INSERT INTO MyAppendQuery (AC_NR) SELECT [MyLinkedTable]![AC_NR] FROM [MyLinkedTable] WHERE ([MyLinkedTable]![AC_NR]= " & "'" & strACNMBR & "'" & ")"
qdf.Sql = strSQLQ
DoCmd.OpenQuery "MyAppendQuery"
Beep
DoCmd.OpenQuery "SummaryType1Query"
DoCmd.OpenQuery "SummaryType2Query"
Beep
[Forms]![DataSelection]![Type1SummarizedData].Requery
[Forms]![DataSelection]![Type1SummarizedData].Requery
Beep
MsgBox "Process Finished ", vbInformation
End Sub