Scenario:
We pull data into a LibreOffice Calc spreadsheet from an MSSQL Databaase.
An admin person goes through and checks the data for validity.
As they go through each row, they want to mark that row as complete in some way and re-upload to the DB, to indicate it’s been checked.
This way, each time they pull the data, they know where they’re up to.
Let’s say we have 4 columns of data:
NAME HOURS UNIQUE_TABLE_ID IS_CHECKED
Fred 10 FredABC Y
Wilma 12 WilmaABC Y
Barney 12 BarneyABC N
Betty 10 BettyABC N
The admin person wants to change cells in the IS_CHECKED column to Y (or N, but theoretically could be any text), then click a button (Macro) to upload this data back into the DB, using the UNIQUE_TABLE_ID to ensure the correct DB entry is updated.
I can update a single row of data using this code as a starting point:
Sub Amend1Record
Sheets = ThisComponent.Sheets
Sheet1 = Sheets.getByIndex(1)
NAME = Sheet1.getCellByPosition(1,1)
NAMETEXT = NAME.String
HOURS = Sheet1.getCellByPosition(2,1)
HOURSTEXT = HOURS.String
UNIQUE_TABLE_ID = Sheet1.getCellByPosition(3,1)
UNIQUE_TABLE_IDTEXT = UNIQUE_TABLE_ID.String
IS_CHECKED = Sheet1.getCellByPosition(4,1)
IS_CHECKEDTEXT = IS_CHECKED.String
Context = CreateUnoService("com.sun.star.sdb.DatabaseContext")
DBName = "Attendance"
DB = Context.getByName(DBName)
Conn = DB.getConnection("","" )
Stmt = Conn.createStatement()
Stmt.executeupdate("update ""AttendanceData"" set ""aNAME"" = '" & NAMETEXT &_
"', ""aHOURS"" = '" & HOURSTEXT &_
"', ""aUNIQUE_TABLE_ID"" = '" & UNIQUE_TABLE_IDTEXT &_
"', ""aIS_CHECKED"" = '" & IS_CHECKEDTEXT &_
"' where ""aUNIQUE_TABLE_ID"" = '" & UNIQUE_TABLE_IDTEXT & "' ")
End Sub
I don’t know how to do multiple (and varying in quantity) rows though.
Can anyone help?
Thanks
James