I have a table with the following fields ID, Device, Doc, Computer. All strings except for ID.
This table would typically look something like this:
1 Epson A4 DellLaptop
2 Canon Small Label DellLaptop
3 Canon LargeLabel DellLaptop
4 Epson A4 Toshiba
5 Brother SmallLabel Toshiba
6
What I am trying to do it to collect the name of the computer, the document selected and the size of the document and through a query, update the table in this way:
Let's say that I go through the code and my variables are Device=Canon, Document=A4 Computer=DellLaptop
The query needs to go to the table and see if the computer "DellLaptop" has any records in the table. In this case it has three. Then see if any of the records have a matching document, which happens once. Then change the printer in the 1st record to Canon so the table would look like this:
1 Canon A4 DellLaptop
2 Canon Small Label DellLaptop
3 Canon LargeLabel DellLaptop
4 Epson A4 Toshiba
5 Brother SmallLabel Toshiba
6
If the computer does not have any records at all (for example, Computer=DellStation Device=Epson Document=SmallLabel) then an entirely new record is created inputing the three variables.
1 Canon A4 DellLaptop
2 Canon Small Label DellLaptop
3 Canon LargeLabel DellLaptop
4 Epson A4 Toshiba
5 Brother SmallLabel Toshiba
6 Epson SmallLabel DellStation
I am aiming to have each printer that each computer uses listed only once alongside the size of the document printed.
I was hoping to do this with the following query:
But this query does not insert any data in the table unless the WHERE condition is met, which means that it does not work for new computers and/or computers which do not have all the document sizes already in the table. In other words, this query UPDATES, but it doe snot enter NEW information. How can I make that happen?
What am I missing?
mafhobb
This table would typically look something like this:
1 Epson A4 DellLaptop
2 Canon Small Label DellLaptop
3 Canon LargeLabel DellLaptop
4 Epson A4 Toshiba
5 Brother SmallLabel Toshiba
6
What I am trying to do it to collect the name of the computer, the document selected and the size of the document and through a query, update the table in this way:
Let's say that I go through the code and my variables are Device=Canon, Document=A4 Computer=DellLaptop
The query needs to go to the table and see if the computer "DellLaptop" has any records in the table. In this case it has three. Then see if any of the records have a matching document, which happens once. Then change the printer in the 1st record to Canon so the table would look like this:
1 Canon A4 DellLaptop
2 Canon Small Label DellLaptop
3 Canon LargeLabel DellLaptop
4 Epson A4 Toshiba
5 Brother SmallLabel Toshiba
6
If the computer does not have any records at all (for example, Computer=DellStation Device=Epson Document=SmallLabel) then an entirely new record is created inputing the three variables.
1 Canon A4 DellLaptop
2 Canon Small Label DellLaptop
3 Canon LargeLabel DellLaptop
4 Epson A4 Toshiba
5 Brother SmallLabel Toshiba
6 Epson SmallLabel DellStation
I am aiming to have each printer that each computer uses listed only once alongside the size of the document printed.
I was hoping to do this with the following query:
Code:
InsertingData = "UPDATE tblPrinterSelection SET Device='" & PrintSel & "', Computer='" & sHostName & "' WHERE Doc='" & DocType & "';"
DoCmd.RunSQL InsertingData
What am I missing?
mafhobb
Last edited: