J
Jessard
Hi,
I am having trouble with the SheetChange event firing more than i would
expect. I have a OWC spreadsheet and a sheetchange event which updates a
cell in the 12th column. Relevant code is listed below. There is nothing in
the 12th cell to begin with.
Sub Spreadsheet1_SheetChange(Sh,Target)
Msgbox("sheetchanged R" & Target.Row & "C" & Target.Column)
Dim str
if ((Target.Row mod 9)=1) then
msgbox("in Target Row R" & Target.Row & "C" & Target.Column)
if Target.Column = 3 Then
msgbox("in Target Column R" & Target.Row & "C" & Target.Column)
Dim rowint, colint
rowint = Target.Row
colint = Target.Column
str = makeUpdate ("CompanyName",rowint,colint,0)
Spreadsheet1.activesheet.cells(rowint,12) = str
end if
end if
End Sub
Function makeUpdate(fieldName,row,col,num)
Dim sql
Dim sa
Dim changeOccurred
sa = false
changeOccurred = false
Dim whereIndex
whereIndex = -1
Dim alreadyIndex
alreadyIndex = -1
if Spreadsheet1.activesheet.cells(row-num,12) <> "" Then
sql = Spreadsheet1.activesheet.cells(row-num,12)
whereIndex = instr(sql," WHERE " & fieldName & " =")
sql = Left(sql,whereIndex)
sa = true
msgbox("in top if")
else
sql = "UPDATE Clients SET "
end if
dim endIndex
endIndex = -1
changeOccurred = true
alreadyIndex = InStr(sql," " & fieldName & " = ")
if alreadyIndex > 0 Then
endIndex = instr(alreadyIndex,sql,",")
if endIndex = 0 Then
endIndex = len(sql)
end if
sql = left(sql,alreadyIndex) & right(sql,len(sql)-endIndex)
sql = sql & " " & fieldName & " = '" &
Spreadsheet1.activesheet.cells(row,col) & "'"
else
if sa=true then
sql = sql & ", " & fieldName & " = '" &
Spreadsheet1.activesheet.cells(row,col) & "'"
else
sql = sql & " "& fieldName & " = '" &
Spreadsheet1.activesheet.cells(row,col) & "'"
end if
end if
if changeOccurred = true Then
makeUpdate = sql & " WHERE ClientID = '" &
Spreadsheet1.activesheet.cells(row-num, 2) & "'"
end if
End Function
Help would be much appreciated.
Thanks,
Jesse
I am having trouble with the SheetChange event firing more than i would
expect. I have a OWC spreadsheet and a sheetchange event which updates a
cell in the 12th column. Relevant code is listed below. There is nothing in
the 12th cell to begin with.
Sub Spreadsheet1_SheetChange(Sh,Target)
Msgbox("sheetchanged R" & Target.Row & "C" & Target.Column)
Dim str
if ((Target.Row mod 9)=1) then
msgbox("in Target Row R" & Target.Row & "C" & Target.Column)
if Target.Column = 3 Then
msgbox("in Target Column R" & Target.Row & "C" & Target.Column)
Dim rowint, colint
rowint = Target.Row
colint = Target.Column
str = makeUpdate ("CompanyName",rowint,colint,0)
Spreadsheet1.activesheet.cells(rowint,12) = str
end if
end if
End Sub
Function makeUpdate(fieldName,row,col,num)
Dim sql
Dim sa
Dim changeOccurred
sa = false
changeOccurred = false
Dim whereIndex
whereIndex = -1
Dim alreadyIndex
alreadyIndex = -1
if Spreadsheet1.activesheet.cells(row-num,12) <> "" Then
sql = Spreadsheet1.activesheet.cells(row-num,12)
whereIndex = instr(sql," WHERE " & fieldName & " =")
sql = Left(sql,whereIndex)
sa = true
msgbox("in top if")
else
sql = "UPDATE Clients SET "
end if
dim endIndex
endIndex = -1
changeOccurred = true
alreadyIndex = InStr(sql," " & fieldName & " = ")
if alreadyIndex > 0 Then
endIndex = instr(alreadyIndex,sql,",")
if endIndex = 0 Then
endIndex = len(sql)
end if
sql = left(sql,alreadyIndex) & right(sql,len(sql)-endIndex)
sql = sql & " " & fieldName & " = '" &
Spreadsheet1.activesheet.cells(row,col) & "'"
else
if sa=true then
sql = sql & ", " & fieldName & " = '" &
Spreadsheet1.activesheet.cells(row,col) & "'"
else
sql = sql & " "& fieldName & " = '" &
Spreadsheet1.activesheet.cells(row,col) & "'"
end if
end if
if changeOccurred = true Then
makeUpdate = sql & " WHERE ClientID = '" &
Spreadsheet1.activesheet.cells(row-num, 2) & "'"
end if
End Function
Help would be much appreciated.
Thanks,
Jesse