I was able to get it originally.Something's wrong.
View attachment 118019
I can see the name of the file, but it does not let me download it and that error message shows up. I suggest you use another service, like Google Drive or even Dropbox.
I was copy-pasting from Google's OCR but it didn't read it correctly, when I typed it myself, it worked. OP translated database and it's attached.I was able to get it originally.
Public Sub CreateCatalog(Optional CatID As Long = 0, Optional subCatID As Long = 0, Optional ActivityID As Long = 0)
Dim strSql As String
Dim qdf As QueryDef
Dim fltr As String
strSql = "SELECT Product, ImagePath FROM tbProducts "
Set qdf = CurrentDb.QueryDefs("qryTempCatalogFilter")
If CatID <> 0 Then fltr = "Category = " & CatID
If subCatID <> 0 Then
fltr = " Subcategory = " & subCatID
End If
If ActivityID <> 0 Then
If CatID = 0 And subCatID = 0 Then
fltr = "Activity = " & ActivityID
Else
fltr = fltr & " AND Acitivity = " & ActivityID
End If
End If
If fltr <> "" Then
strSql = strSql & " WHERE " & fltr
End If
qdf.SQL = strSql & " Order By Category, Subcategory, Product"
' Debug.Print qdf.SQL
CreateTempTable
'currentdb.TableDefs.Refresh
End Sub
Public Sub CreateTempTable()
Dim PathLead As String
Dim rsTemp As DAO.Recordset
Dim rsSource As DAO.Recordset
Dim i As Integer
Dim Path As String
Set rsTemp = CurrentDb.OpenRecordset("tblTempCatalog")
Set rsSource = CurrentDb.OpenRecordset("qryTempCatalogFilter")
PathLead = CurrentProject.Path & "\img\"
CurrentDb.Execute "qryClearTempCatalog"
Do While Not rsSource.EOF
rsTemp.AddNew
rsTemp.Fields("ImagePath1") = PathLead & rsSource!ImagePath
rsTemp.Fields("ImageName1") = PlainText(rsSource!Product)
If Not rsSource.EOF Then rsSource.MoveNext
If Not rsSource.EOF Then
rsTemp.Fields("ImagePath2") = PathLead & rsSource!ImagePath
rsTemp.Fields("ImageName2") = PlainText(rsSource!Product)
End If
If Not rsSource.EOF Then rsSource.MoveNext
If Not rsSource.EOF Then
rsTemp.Fields("ImagePath3") = PathLead & rsSource!ImagePath
rsTemp.Fields("ImageName3") = PlainText(rsSource!Product)
End If
rsTemp.Update
If Not rsSource.EOF Then rsSource.MoveNext
Loop
End Sub
Thank you very much MajP. Right now I'm studying your instructions in the thread you pointed out to me to figure out how to correct normalisation errors. Maybe I'll create another thread? Thanks againThe code first creates a query def sql so you can filter the records. It then loops the filtered records and puts the values into the temp table.
Here is the basic code to do that.
Code:Public Sub CreateCatalog(Optional CatID As Long = 0, Optional subCatID As Long = 0, Optional ActivityID As Long = 0) Dim strSql As String Dim qdf As QueryDef Dim fltr As String strSql = "SELECT Product, ImagePath FROM tbProducts " Set qdf = CurrentDb.QueryDefs("qryTempCatalogFilter") If CatID <> 0 Then fltr = "Category = " & CatID If subCatID <> 0 Then fltr = " Subcategory = " & subCatID End If If ActivityID <> 0 Then If CatID = 0 And subCatID = 0 Then fltr = "Activity = " & ActivityID Else fltr = fltr & " AND Acitivity = " & ActivityID End If End If If fltr <> "" Then strSql = strSql & " WHERE " & fltr End If qdf.SQL = strSql & " Order By Category, Subcategory, Product" ' Debug.Print qdf.SQL CreateTempTable 'currentdb.TableDefs.Refresh End Sub Public Sub CreateTempTable() Dim PathLead As String Dim rsTemp As DAO.Recordset Dim rsSource As DAO.Recordset Dim i As Integer Dim Path As String Set rsTemp = CurrentDb.OpenRecordset("tblTempCatalog") Set rsSource = CurrentDb.OpenRecordset("qryTempCatalogFilter") PathLead = CurrentProject.Path & "\img\" CurrentDb.Execute "qryClearTempCatalog" Do While Not rsSource.EOF rsTemp.AddNew rsTemp.Fields("ImagePath1") = PathLead & rsSource!ImagePath rsTemp.Fields("ImageName1") = PlainText(rsSource!Product) If Not rsSource.EOF Then rsSource.MoveNext If Not rsSource.EOF Then rsTemp.Fields("ImagePath2") = PathLead & rsSource!ImagePath rsTemp.Fields("ImageName2") = PlainText(rsSource!Product) End If If Not rsSource.EOF Then rsSource.MoveNext If Not rsSource.EOF Then rsTemp.Fields("ImagePath3") = PathLead & rsSource!ImagePath rsTemp.Fields("ImageName3") = PlainText(rsSource!Product) End If rsTemp.Update If Not rsSource.EOF Then rsSource.MoveNext Loop End Sub
I called the method CreateTempTable but it should be called FillTempTable, because the temp table exists and you are just filling it like a grid.
Thanks MajP for helping me try to trace the error back to Access abc. Looking at your screenshots I wondered why you leave the tbProductsSubCategories table ‘isolated’, when I created it (with the intention of creating a join table) it had seemed the most correct choice to hold together the many-to-many relationships I seemed to identify in my settings. After your posts I began to doubt that these are indeed many-to-many relationships and reviewed the whole thing theoretically, this can be summarised as follows:I will asks questions one at a time.
A supplier can supply lots of goods I would think in different categories. Currently in the supplier table you have foreign keys to Category, Activity, SubCategory.
You have a junction table tbCategorySupplier which makes sense. That supplier makes different categories of things. Now you can filter on that supplier when assigning to a product based on category.
However, having ActivityID_FK and SubCategory_FK makes no sense in the supplier table. Are you thinking you need to filter more.
If so the junction table would need to likely be tbSubCategoriesSupplier
So instead of filtering on sports equipment you can filter on more detail "volley ball nets". Just depends what you want to do.
Soprattutto, ho il terrore di modificare una struttura che sembra funzionare perché ho paura di non sapere come gestire le conseguenze di questi cambiamenti. Utilizzo solo questo database, con esso gestisco i prodotti, il catalogo (infatti la richiesta della visualizzazione dell'immagine con cui ho aperto questo thread era proprio per avere una soluzione più snella per la visualizzazione delle porzioni filtrate di questo catalogo) gli ordini e i preventivi. Se lo modifico per rendere la struttura corretta a livello tecnico (come mi piacerebbe molto fare) e tuttavia non funziona più, il mio lavoro ne risentirebbe e questo mi spaventa, a meno che non ci sia un modo per correggere la struttura (normalizzazione ad esempio) senza rischiare di demolire le fondamentaNota speciale riguardante l'istituzione di una relazione Molti a Molti di cui MajP ha parlato; Il tempo e l'impegno necessari per immettere correttamente i dati per le relazioni sono spesso di gran lunga superiori al tempo necessario per la codifica. Con 7600 prodotti questo significa che per OGNI articolo devi decidere se ha senso averlo attaccato a OGNI categoria. In molti casi questo è molto più difficile della codifica. Troppi link sono inutili quanto troppo pochi.
Potresti voler dare un'occhiata a tutto il resto. Guarderei il feedback dei clienti per vedere se vale la pena inserire i dati richiesti.
I left it because was not sure where you were going with it. It may now make sense.I wondered why you leave the tbProductsSubCategories table ‘isolated’, when I created it (with the intention of creating a join table) it had seemed the most correct choice to hold together the many-to-many relationships I seemed to identify in my settings