Hello everyone, I am working on Access 2003 to create a process in which I will be able to filter the data from one table (in my case, named DSO) in to another temporary table (tTable2) for viewing by the user.
In my application, a user will log in and be directed to a main page where as of now they have three options:
1.) View/Edit the DSO Table (which has 399 records, at this moment)
2.) Filter the DSO table (in to a temporary table, tTable2)
3.) View the filtered table (tTable2)
Now on to my code/problem:
I have a form in which 10 checkboxes are shown, the user is to select which relevent data they would need and the click the button to generate this data. Basically my code is supposed to check which boxes are checked and then using that data it is to append data from the original table, DSO, in to a temporary table, tTable2.
This process works fine and well, how I wanted to, however, now I run into my problem. The issue is duplicates. The data I need appended to the new temporary table works fine, however, there are some columns that have multiple instances of data in them. Therefore, those datasets have recorded multiple times. Or, that is how I have evaluated the problem that is occuring, and instead of speculating I will post my code:
As of now my code is focusing on the first 6 checkboxes, the locations: Exton, Plano..etc, instead of the Service/Sales and System. Once I figure that portion out I will expand to the rest.
An idea I had to fix this problem was to select all the duplicate rows and delete one set of the duplicates. I am not sure how to follow through with that idea.
Another idea tried to use DISTINCTROW SQL, but that also ended up not working.
I am new to the Access, VB, and SQL worlds, so some of my code may seem..newbish? Any help would be appreciated, or if another idea to perform the same task in a more efficient/easier way would be great as well.
Thanks you!
In my application, a user will log in and be directed to a main page where as of now they have three options:
1.) View/Edit the DSO Table (which has 399 records, at this moment)
2.) Filter the DSO table (in to a temporary table, tTable2)
3.) View the filtered table (tTable2)
Now on to my code/problem:
I have a form in which 10 checkboxes are shown, the user is to select which relevent data they would need and the click the button to generate this data. Basically my code is supposed to check which boxes are checked and then using that data it is to append data from the original table, DSO, in to a temporary table, tTable2.
This process works fine and well, how I wanted to, however, now I run into my problem. The issue is duplicates. The data I need appended to the new temporary table works fine, however, there are some columns that have multiple instances of data in them. Therefore, those datasets have recorded multiple times. Or, that is how I have evaluated the problem that is occuring, and instead of speculating I will post my code:
Code:
Public Sub searchCmd_Click()
Dim SQL, strPlano, strPrc, strExton, strBcp, strRslteng, strRsltspn, strService, strSales, strId, strFf As String
'Removes previous holder tTable2
SQL = "DROP TABLE tTable2"
CurrentDb.Execute (SQL)
'Create a temp table to filter data to (columns)
SQL = "SELECT DSO.* INTO tTable2 FROM DSO"
CurrentDb.Execute (SQL)
'Clears the information (rows)
CurrentDb.Execute "Delete * from tTable2"
'The following set of if statements find the value of the checkbox (true/false) and assigns a string associated
'with that checkbox either a delimiter, %, or the string value of what the column associated is named
'Checks if exton checkbox is true/fale
If extonCheck.Value = 0 Then
strExton = "%"
Else
strExton = "Exton"
End If
'Checks if plano checkbox is true/fale
If planoCheck.Value = 0 Then
strPlano = "%"
Else
strPlano = "Plano"
End If
'Checks if PRC checkbox is true/fale
If prcCheck.Value = 0 Then
strPrc = "%"
Else
strPrc = "PRC"
End If
'Checks if BCP checkbox is true/fale
If bcpCheck.Value = 0 Then
strBcp = "%"
Else
strBcp = "BCP"
End If
'Checks if rslteng checkbox is true/fale
If rsltEngCheck.Value = 0 Then
strRslteng = "%"
Else
strRslteng = "RSLT English"
End If
'Checks if rsltspn checkbox is true/fale
If rsltSpnCheck.Value = 0 Then
strRsltspn = "%"
Else
strRsltspn = "RSLT SPN"
End If
'Checks if service checkbox is true/fale
If serviceCheck.Value = 0 Then
strService = "%"
Else
strService = "Service"
End If
'Checks if sales checkbox is true/fale
If salesCheck.Value = 0 Then
strSales = "%"
Else
strSales = "Sales"
End If
'Checks if id checkbox is true/fale
If idCheck.Value = 0 Then
strId = "%"
Else
strId = "ID"
End If
'Checks if ff checkbox is true/fale
If ffCheck.Value = 0 Then
strFf = "%"
Else
strFf = "FF"
End If
'The next set of if statements append data to the tTable2
'The SQL used for the insertions uses the logic that if a box is checked then
'all slots where that specific column is not " " (blank) then it will be inserted into the
'temporary table; tTable2. This iterates through each checkbox, using if statements, until
'all have been iterated through. Result is append from DSO into tTable2 wherever necessary
'***problem: duplicates are created
If strExton <> "%" Then 'if checked, append info to tTable2
SQL = "INSERT INTO tTable2 SELECT * FROM DSO WHERE " & strExton & "<>"" "" "
CurrentDb.Execute (SQL)
End If
If strPlano <> "%" Then 'if checked, append info to tTable2
SQL = "INSERT INTO tTable2 SELECT * FROM DSO WHERE " & strPlano & "<>"" "" "
CurrentDb.Execute (SQL)
End If
If strPrc <> "%" Then 'if checked, append info to tTable2
SQL = "INSERT INTO tTable2 SELECT * FROM DSO WHERE " & strPrc & "<>"" "" "
CurrentDb.Execute (SQL)
End If
If strBcp <> "%" Then 'if checked, append info to tTable2
SQL = "INSERT INTO tTable2 SELECT * FROM DSO WHERE " & strBcp & "<>"" "" "
CurrentDb.Execute (SQL)
End If
If strRslteng <> "%" Then 'if checked, append info to tTable2
SQL = "INSERT INTO tTable2 SELECT * FROM DSO WHERE [" & strRslteng & "]<>"" "" "
CurrentDb.Execute (SQL)
End If
If strRsltspn <> "%" Then 'if checked, append info to tTable2
SQL = "INSERT INTO tTable2 SELECT * FROM DSO WHERE [" & strRsltspn & "]<>"" "" "
CurrentDb.Execute (SQL)
End If
'Refresh the form
Form_filterForm.Requery
'Signify the end of the process to the user
MsgBox "The filtering is complete."
End Sub
As of now my code is focusing on the first 6 checkboxes, the locations: Exton, Plano..etc, instead of the Service/Sales and System. Once I figure that portion out I will expand to the rest.
An idea I had to fix this problem was to select all the duplicate rows and delete one set of the duplicates. I am not sure how to follow through with that idea.
Another idea tried to use DISTINCTROW SQL, but that also ended up not working.
I am new to the Access, VB, and SQL worlds, so some of my code may seem..newbish? Any help would be appreciated, or if another idea to perform the same task in a more efficient/easier way would be great as well.
Thanks you!