S
SwissMiss
Need to use the same functionality to fill a table with info. But do not know
the name of the table before hand.
The code I created gets the error message "Item not found in this
collection. error 3265" as if it is not finding the table.
However if I copy the generated strSQL from the intermediate window and
paste it in a query, it works fine.
What do I need to do with my code, which is posted below. All help
appreciated.
Dim strSQL As String, myTable As String, qdf As DAO.QueryDef, myYear As
Integer
myTable = "tblM_IUFList" & "_" & Me.cboIUFList.Column(1)
myYear = Me.cboIUFlistYear
CurrentDb.TableDefs.Refresh
'either delete stuff from current table of create new one
If doesTableFormExist(myTable, "Table") = True Then
strSQL = "DELETE [" & myTable & "].* FROM [" & myTable & "];"
Set qdf = CurrentDb.QueryDefs(strSQL)
qdf.Execute dbSeeChanges
Else
DoCmd.CopyObject , myTable, acTable, "tblM_IUFListModel"
CurrentDb.TableDefs.Refresh
End If
'update org ids and info
strSQL = "INSERT INTO [" & myTable & "] ( Organization_ID, ReportOrder,
Region, SortOrder, CountryName, Name, MergedOrgID, SectorName, LastYear )" &
vbCrLf
strSQL = strSQL & "SELECT DISTINCT tblOrganizations.Organization_Id,
tblReportRegion.ReportOrder, tblReportRegion.English,
IIf([tblOrganizations]![Organization_Type_Id]=2,2,1) AS Expr1,
tblCountry.Country, [tblOrganizations]![Organization_Name] & IIf(Not
IsNull([tblOrganizations]![Abbreviation]),' [' &
[tblOrganizations]![Abbreviation] & ']','') AS Expr2,
tblOrganizations.MergedOrgID, tblIUF_List.List_Name, " & myYear & " AS Expr3"
& vbCrLf
strSQL = strSQL & "FROM tblReportRegion INNER JOIN ((tblCountry INNER JOIN
tblOrganizations ON tblCountry.Country_Id = tblOrganizations.Country_Id)
INNER JOIN (tblContacts INNER JOIN (tblIUF_List INNER JOIN
tblIUF_List_LinkedContacts ON tblIUF_List.List_Id =
tblIUF_List_LinkedContacts.List_Id) ON tblContacts.Contact_Id =
tblIUF_List_LinkedContacts.Contact_Id) ON tblOrganizations.Organization_Id =
tblContacts.Organization_Id) ON tblReportRegion.ReportRegion_ID =
tblCountry.ReportRegion_ID" & vbCrLf
strSQL = strSQL & "WHERE (((tblIUF_List_LinkedContacts.List_Id)= " &
Me.cboIUFList & "))" & vbCrLf
strSQL = strSQL & "ORDER BY tblOrganizations.Organization_Id;"
Set qdf = CurrentDb.QueryDefs(strSQL)
qdf.Execute dbSeeChanges
Set qdf = Nothing
etc.
the name of the table before hand.
The code I created gets the error message "Item not found in this
collection. error 3265" as if it is not finding the table.
However if I copy the generated strSQL from the intermediate window and
paste it in a query, it works fine.
What do I need to do with my code, which is posted below. All help
appreciated.
Dim strSQL As String, myTable As String, qdf As DAO.QueryDef, myYear As
Integer
myTable = "tblM_IUFList" & "_" & Me.cboIUFList.Column(1)
myYear = Me.cboIUFlistYear
CurrentDb.TableDefs.Refresh
'either delete stuff from current table of create new one
If doesTableFormExist(myTable, "Table") = True Then
strSQL = "DELETE [" & myTable & "].* FROM [" & myTable & "];"
Set qdf = CurrentDb.QueryDefs(strSQL)
qdf.Execute dbSeeChanges
Else
DoCmd.CopyObject , myTable, acTable, "tblM_IUFListModel"
CurrentDb.TableDefs.Refresh
End If
'update org ids and info
strSQL = "INSERT INTO [" & myTable & "] ( Organization_ID, ReportOrder,
Region, SortOrder, CountryName, Name, MergedOrgID, SectorName, LastYear )" &
vbCrLf
strSQL = strSQL & "SELECT DISTINCT tblOrganizations.Organization_Id,
tblReportRegion.ReportOrder, tblReportRegion.English,
IIf([tblOrganizations]![Organization_Type_Id]=2,2,1) AS Expr1,
tblCountry.Country, [tblOrganizations]![Organization_Name] & IIf(Not
IsNull([tblOrganizations]![Abbreviation]),' [' &
[tblOrganizations]![Abbreviation] & ']','') AS Expr2,
tblOrganizations.MergedOrgID, tblIUF_List.List_Name, " & myYear & " AS Expr3"
& vbCrLf
strSQL = strSQL & "FROM tblReportRegion INNER JOIN ((tblCountry INNER JOIN
tblOrganizations ON tblCountry.Country_Id = tblOrganizations.Country_Id)
INNER JOIN (tblContacts INNER JOIN (tblIUF_List INNER JOIN
tblIUF_List_LinkedContacts ON tblIUF_List.List_Id =
tblIUF_List_LinkedContacts.List_Id) ON tblContacts.Contact_Id =
tblIUF_List_LinkedContacts.Contact_Id) ON tblOrganizations.Organization_Id =
tblContacts.Organization_Id) ON tblReportRegion.ReportRegion_ID =
tblCountry.ReportRegion_ID" & vbCrLf
strSQL = strSQL & "WHERE (((tblIUF_List_LinkedContacts.List_Id)= " &
Me.cboIUFList & "))" & vbCrLf
strSQL = strSQL & "ORDER BY tblOrganizations.Organization_Id;"
Set qdf = CurrentDb.QueryDefs(strSQL)
qdf.Execute dbSeeChanges
Set qdf = Nothing
etc.