Insert Picture from Picturebox to excel - excel

I have a code which inserting all information from textboxes to excel file.
What I trying to do to using this code also add a picture from picturebox.
So in each row in the right column will be a picture.
But I having a problem to adjust a code.
Could anyone help me with that?
Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=DATA\DATA.xlsm;Extended Properties = ""Excel 12.0 Xml;HDR=YES"""
'Create an INSERT INTO SQL statement
Dim insertStatement As String = "INSERT INTO [DATA$] ([WEEK], [DATE], [PART NAME], [PART NUMBER], [REASON FOR SCRAP], [LINE], [MACHINE], [TOOLING], [MTO], [QTY], [WHO SCRAP IT]) VALUES ('" + WEEK_TEXT.Text + "','" + DATEE_TEXT.Text + "','" + PARTNAME_TEXT.Text + "','" + PARTNUMBER_TEXT.Text + "','" + SCRAP_REASON_TEXT.Text + "','" + LINE_text.Text + "','" + MACHINE_TEXT.Text + "','" + SIDE_TEXT.Text + "','" + MTO_TEXT.Text + "','" + QUANTITY_TEXT.Text + "','" + TL_TS_TEXT.Text + "')"
Dim insertStatement1 As String = "INSERT INTO [QAD DATA$] ([WEEK], [DATE], [PART NAME], [QAD NUMBER], [REASON FOR SCRAP], [LINE], [MACHINE], [TOOLING], [MTO], [QTY], [WHO SCRAP IT]) VALUES ('" + WEEK_TEXT.Text + "','" + DATEE_TEXT.Text + "','" + PictureBox1.I + "','" + QAD_NUMBER_TEXT.Text + "','" + SCRAP_REASON_TEXT.Text + "','" + LINE_text.Text + "','" + MACHINE_TEXT.Text + "','" + SIDE_TEXT.Text + "','" + MTO_TEXT.Text + "','" + QUANTITY_TEXT.Text + "','" + TL_TS_TEXT.Text + "')"
'Create a connection object to connect to the Excel Workbook
Dim connection As New OleDbConnection(connectionString)
Dim connection1 As New OleDbConnection(connectionString)
'Create a command object that will execute the insert statement
Dim command As New OleDbCommand(insertStatement, connection)
Dim command1 As New OleDbCommand(insertStatement1, connection1)
'Open the connection, execute the statement and close the connection
connection.Open()
connection1.Open()
command.ExecuteNonQuery()
command1.ExecuteNonQuery()
connection.Close()
connection1.Close()
'Dispose of the connection and command objects
connection.Dispose()
command.Dispose()
command1.Dispose()

Related

Making VBA script to map Excel fields to Project more efficient

So I have Microsoft Project file with around 600 rows of parent tasks. I need to import new data from Excel into this Project file using the Import Wizard and then run a script that creates four milestones below each parent task and then maps date and text fields from the Excel file into the correct cells in the Project file. If the parent task already has four milestones (and is not a new parent task) then the script updates the date and text fields for the task with the new data. I used the following script to accomplish this, and it works. However, it takes over 10 minutes to run. I know this is not the most efficient way to write this script. Can anyone help me modify the script so it takes less time to run?
Sub InsertSubTask()
Dim tsk As Task
For Each tsk In ActiveProject.Tasks
If tsk.Flag1 And tsk.OutlineChildren.Count = 0 Then
With ActiveProject
tsk.Name = tsk.Text5 + " " + "-" + tsk.Name
.Tasks.Add tsk.Name + " " + "-" + " " + "Milestone 1", tsk.ID + 1
.Tasks.Add tsk.Name + " " + "-" + " " + "Milestone 2", tsk.ID + 2
.Tasks.Add tsk.Name + " " + "-" + " " + "Milestone3", tsk.ID + 3
.Tasks.Add tsk.Name + " " + "-" + " " + "Milestone4", tsk.ID + 4
.Tasks(tsk.ID + 1).OutlineIndent
.Tasks(tsk.ID + 2).OutlineIndent
.Tasks(tsk.ID + 3).OutlineIndent
.Tasks(tsk.ID + 4).OutlineIndent
.Tasks(tsk.ID + 1).Start = DateAdd("d", -1, tsk.Date4)
.Tasks(tsk.ID + 2).Start = tsk.Date2
.Tasks(tsk.ID + 3).Start = tsk.Date4
.Tasks(tsk.ID + 4).Start = tsk.Date3
tsk.Text10 = "Example"
.Tasks(tsk.ID + 1).Text10 = "Example"
.Tasks(tsk.ID + 2).Text10 = "Example"
.Tasks(tsk.ID + 3).Text10 = "Example"
.Tasks(tsk.ID + 4).Text10 = "Example"
tsk.Text18 = "MILESTONE"
.Tasks(tsk.ID + 2).Text18 = "MILESTONE"
.Tasks(tsk.ID + 1).BaselineStart = tsk.Date5
.Tasks(tsk.ID + 2).BaselineStart = tsk.Date2
.Tasks(tsk.ID + 3).BaselineStart = tsk.Date4
.Tasks(tsk.ID + 4).BaselineFinish = tsk.Date3
.Tasks(tsk.ID + 2).ActualFinish = tsk.Date7
End With
End If
Next tsk
For Each tsk In ActiveProject.Tasks
If tsk.Flag1 And tsk.OutlineChildren.Count = 4 Then
With ActiveProject
.Tasks(tsk.ID + 1).Start = DateAdd("d", -1, tsk.Date4)
.Tasks(tsk.ID + 2).Start = tsk.Date2
.Tasks(tsk.ID + 3).Start = tsk.Date4
.Tasks(tsk.ID + 4).Start = tsk.Date3
.Tasks(tsk.ID + 1).BaselineStart = tsk.Date5
.Tasks(tsk.ID + 2).BaselineStart = tsk.Date2
.Tasks(tsk.ID + 3).BaselineStart = tsk.Date4
.Tasks(tsk.ID + 4).BaselineFinish = tsk.Date3
.Tasks(tsk.ID + 2).ActualFinish = tsk.Date7
End With
End If
Next tsk
End Sub

(LotusScript)How can update sql in notes document button?

I need to update some fields in the oracle database, like the following code.
I set the condition to write the value, but only one data can update.
How to update the data within the conditions?
Sub Click(Source As Button)
Dim con2 As New ODBCConnection
Dim qry2 As New ODBCQuery
Dim result2 As New ODBCResultSet
If con2.ConnectTo("***","***","***") Then
Set qry2.connection = con2
Set result2.query = qry2
mysql2 = "SELECT * FROM CB_A"
mysql2 = mysql2 + " WHERE PONUM = 'FC950102' OR PONUM = 'FT940141'"
qry2.SQL = mysql2
result2.Execute
If result2.IsResultSetAvailable Then
result2.FirstRow
sqlponum = result2.GetValue("PONUM")
sqlcomp = result2.GetValue("PUR_COMP_NAME")
End If
result2.LastRow
For i = 1 To result2.NumRows
result2.CurrentRow = i
sqlponum = result2.GetValue("PONUM")
Msgbox sqlponum + Chr(10) + sqlcomp
If j >= 0 And k >= 0 Then
mysql2 = "UPDATE CB_A SET ORDER_FLAG = '" + order_flag + "' , AUCTION_STATUS = '" + auction_status + "' , AUCTION_DATE = '" + tempaucdate + "' , AUCTION_PLACE = '" + AP(j) + "' , AUCTION_TIME = '" + AT(k) + "'"
mysql2 = mysql2 + " WHERE PONUM = '" + sqlponum + "'"
k = k + 1
If k = 4 Then
j = j + 1
k = 0
End If
qry2.SQL = mysql2
result2.Execute
End If
Next
End If
result2.Close(db_close)
con2.Disconnect
End Sub
I edited some coding to achieved what I want to do.
In the For...Next loop, has "result.Execute", it will that mysql1 to be reset.
So, I copied and pasted mysql1 in For...Next loop.
Then it's can be work.
The following is the final coding...
If con2.ConnectTo("***","***","***") Then
Set qry2.connection = con2
Set result2.query = qry2
mysql1 = "SELECT * FROM CB_A WHERE ORDER_FLAG = '1' AND AUCTION_STATUS = '0'"
qry2.SQL = mysql1
result2.Execute
result2.LastRow
For i = 1 To result2.NumRows
result2.CurrentRow = i
mysql1 = "SELECT * FROM CB_A WHERE ORDER_FLAG = '1' AND AUCTION_STATUS = '0'"
qry2.SQL = mysql1
result2.Execute
sqlponum = result2.GetValue("PONUM")
sqlcomp = result2.GetValue("PUR_COMP_NAME")
Msgbox sqlponum + Chr(10) + sqlcomp
If j >= 0 And k >= 0 Then
mysql2 = "UPDATE CB_A SET ORDER_FLAG = '" + order_flag + "' , AUCTION_STATUS = '" + auction_status + "' , AUCTION_DATE = '" + tempaucdate + "' , AUCTION_PLACE = '" + AP(j) + "' , AUCTION_TIME = '" + AT(k) + "'"
mysql2 = mysql2 + " WHERE PONUM = '" + sqlponum + "' AND PUR_COMP_NAME = '" + sqlcomp + "'"
qry2.SQL = mysql2
result2.Execute
k = k + 1
If k = 4 Then
j = j + 1
k = 0
End If
End If
Next
End If

How to write text file in python3.x?

I am unable to write to a text file. My function looks like this. The file is created but after running the code the file remains empty. I am unable to figure out what the problem is.
def compare(prjCode, prjName, stCode, stName, dCode, dName, sdCode, sdName):
with open('C:\\Users\\NCOG1\\Desktop\\test.txt', 'w') as f:
percentMatch = 0
sdLen = len(sdName)
prjLen = len(prjName)
if (sdLen > prjLen):
if ((sdName.find(prjName) != -1)):
res = sdName.index(prjName)
percentMatch = (prjLen/sdLen)*100
#print(prjCode,prjName,sdCode,sdName,str(round(percentMatch)),stCode, stName, dCode, dName)
#print(prjCode + "," + prjName + "," + sdCode + "," + sdName + str(round(percentMatch)) + "," + stCode + "," + dCode + "," + sdCode)
f.write(prjCode + "," + prjName + "," + sdCode + "," + sdName + "," + str(round(percentMatch)) + "," + stCode + "," + stName + "," + dCode + "," + dName + "%\n")
else:
res = 0
#print(res)
elif (prjLen >= sdLen):
if ((prjName.find(sdName) != -1)):
res = prjName.index(sdName)
percentMatch = (sdLen/prjLen)*100
#print(prjCode,prjName,sdCode,sdName,str(round(percentMatch)),stCode, stName, dCode, dName)
#print(prjCode + "," + prjCode + "," + sdCode + "," + sdName + str(round(percentMatch) + "," stCode + "," + dCode + "," + sdCode)
f.write(prjCode + "," + prjName + "," + sdCode + "," + sdName + "," + str(round(percentMatch)) + "," + stCode + "," + stName + "," + dCode + "," + dName + "%\n")
else:
res = 0
#print(res)
f.close()
1.For to write something in file you need to convert those text or int to String which you didn't do that that's the main problem
2.The path which you types its not rendered because its not identified as a string for that you need to convert your path into raw string for that you need to append "r" before starting of the path which I mentioned in corrected code.
3.For example i call function compare() for dummy data, now check below code and try to run and let me know if you have any doubt.
def compare(prjCode, prjName, stCode, stName, dCode, dName, sdCode, sdName):
with open(r'C:\\Users\\NCOG1\\Desktop\\test.txt', 'w') as f:
percentMatch = 0
sdLen = len(sdName)
prjLen = len(prjName)
if (sdLen > prjLen):
if ((sdName.find(prjName) != -1)):
res = sdName.index(prjName)
percentMatch = (prjLen/sdLen)*100
#print(prjCode,prjName,sdCode,sdName,str(round(percentMatch)),stCode, stName, dCode, dName)
#print(prjCode + "," + prjName + "," + sdCode + "," + sdName + str(round(percentMatch)) + "," + stCode + "," + dCode + "," + sdCode)
f.write(str(prjCode) + "," + prjName + "," + str(sdCode) + "," + sdName + "," + str(round(percentMatch)) + "," + str(stCode) + "," + stName + "," + str(dCode) + "," + str(dName) + "%\n")
else:
res = 0
#print(res)
elif (prjLen >= sdLen):
if ((prjName.find(sdName) != -1)):
res = prjName.index(sdName)
percentMatch = (sdLen/prjLen)*100
#print(prjCode,prjName,sdCode,sdName,str(round(percentMatch)),stCode, stName, dCode, dName)
#print(prjCode + "," + prjCode + "," + sdCode + "," + sdName + str(round(percentMatch) + "," stCode + "," + dCode + "," + sdCode)
f.write(str(prjCode) + "," + prjName + "," + str(sdCode) + "," + sdName + "," + str(round(percentMatch)) + "," + str(stCode) + "," + stName + "," + str(dCode) + "," + str(dName) + "%\n")
else:
res = 0
#print(res)
compare(1,"harsh",0,"fff",34,32,78,"hharshbhut")

Exporting values from multiple documents into Excel Spreadsheet

How can I gather the information for each person, store it, get the information for the next person, store it and then place all of the information on the spreadsheet?
Sub Initialize
Dim s As New NotesSession
Dim ws As New NotesUIWorkspace
Dim db As NotesDatabase
Dim lspTrainingDb As NotesDatabase
Dim view As NotesView
Dim uiView As NotesUIView
Dim childView As NotesView
Dim trainView As NotesView
Dim doc As NotesDocument
Dim uiDoc As NotesUIDocument
Dim childDoc As NotesDocument
Dim trainDoc As NotesDocument
Dim dc As NotesDocumentCollection
Dim dcTrain As NotesDocumentCollection
Dim TotalDocs As Long
Dim awards(24) As Variant
Dim commendations(74) As Variant
Dim xlArray() As String
Dim experience1 As Variant
Dim timeInGrade1 As Variant
Dim fullName As Variant
Dim allAwards As String
Dim allCommendations As String
Dim allTraining As String
Dim docKey As Variant
Dim vRecertify As Variant
Set db = s.CurrentDatabase
arrayDocs% = 0
Set uiView = ws.currentview
Set dc = uiView.documents
If(dc.Count = 0) Then
MessageBox "Please select an officer. (To select a document, place a check mark in the column preceding the document)",48,"Error:"
Exit Sub
End If
'Get field values from the LSP Training Records database
Set profileDoc = db.GetProfileDocument("ProfileDocument")
LSPTrainingServer$ = profileDoc.GetItemValue("LSPTrainingDbServer")(0)
LSPTrainingDbName$ = profileDoc.GetItemValue("LSPTrainingDbName")(0)
Set lspTrainingDb = New NotesDatabase(LSPTrainingServer$, LSPTrainingDbName$)
Set trainView = lspTrainingDb.GetView("(DataNoSpreadsheetView)")
' Set view = db.GetView("All Docs By Name")
Set doc = dc.GetFirstDocument
While Not(doc Is Nothing)
docKey = doc.GetItemValue("datanum")
experience1 = doc.GetItemValue("HireDate")
texperience1 = CStr(experience1(0))
timeInGrade1 = doc.GetItemValue("RankDate")
timeInGrade1 = CStr(timeInGrade1(0))
fullName = doc.GetItemValue("FullName")
tfullName = CStr(fullName(0))
physicalCity = doc.GetItemValue("PhysicalCity")
tPhysicalCity = CStr(physicalCity(0))
Set children = doc.Responses
Set childDoc = children.GetFirstDocument
Do Until childDoc Is Nothing
If childDoc.Form(0) = "Awards" Then
'Award Year fields
awardYear1 = childDoc.GetItemValue("AwardYear_1")
tawardYear1 = CStr(awardYear1(0))
awardYear2 = childDoc.GetItemValue("AwardYear_2")
tawardYear2 = CStr(awardYear2(0))
awardYear3 = childDoc.GetItemValue("AwardYear_3")
tawardYear3 = CStr(awardYear3(0))
awardYear4 = childDoc.GetItemValue("AwardYear_4")
tawardYear4 = CStr(awardYear4(0))
awardYear5 = childDoc.GetItemValue("AwardYear_5")
tawardYear5 = CStr(awardYear5(0))
awardYear6 = childDoc.GetItemValue("AwardYear_6")
tawardYear6 = CStr(awardYear6(0))
awardYear7 = childDoc.GetItemValue("AwardYear_7")
tawardYear7 = CStr(awardYear7(0))
awardYear8 = childDoc.GetItemValue("AwardYear_8")
tawardYear8 = CStr(awardYear8(0))
awardYear9 = childDoc.GetItemValue("AwardYear_9")
tawardYear9 = CStr(awardYear9(0))
awardYear10 = childDoc.GetItemValue("AwardYear_10")
tawardYear10 = CStr(awardYear10(0))
awardYear11 = childDoc.GetItemValue("AwardYear_11")
tawardYear11 = CStr(awardYear11(0))
awardYear12 = childDoc.GetItemValue("AwardYear_12")
tawardYear12 = CStr(awardYear12(0))
awardYear13 = childDoc.GetItemValue("AwardYear_13")
tawardYear13 = CStr(awardYear13(0))
awardYear14 = childDoc.GetItemValue("AwardYear_14")
tawardYear14 = CStr(awardYear14(0))
awardYear15 = childDoc.GetItemValue("AwardYear_15")
tawardYear15 = CStr(awardYear15(0))
awardYear16 = childDoc.GetItemValue("AwardYear_16")
tawardYear16 = CStr(awardYear16(0))
awardYear17 = childDoc.GetItemValue("AwardYear_17")
tawardYear17 = CStr(awardYear17(0))
awardYear18 = childDoc.GetItemValue("AwardYear_18")
tawardYear18 = CStr(awardYear18(0))
awardYear19 = childDoc.GetItemValue("AwardYear_19")
tawardYear19 = CStr(awardYear19(0))
awardYear20 = childDoc.GetItemValue("AwardYear_20")
tawardYear20 = CStr(awardYear20(0))
awardYear21 = childDoc.GetItemValue("AwardYear_21")
tawardYear21 = CStr(awardYear21(0))
awardYear22 = childDoc.GetItemValue("AwardYear_22")
tawardYear22 = CStr(awardYear22(0))
awardYear23 = childDoc.GetItemValue("AwardYear_23")
tawardYear23 = CStr(awardYear23(0))
awardYear24 = childDoc.GetItemValue("AwardYear_24")
tawardYear24 = CStr(awardYear24(0))
awardYear25 = childDoc.GetItemValue("AwardYear_25")
tawardYear25 = CStr(awardYear25(0))
'Award Type fields
awardType1 = childDoc.GetItemValue("AwardType_1")
tawardType1 = CStr(awardType1(0))
awardType2 = childDoc.GetItemValue("AwardType_2")
tawardType2 = CStr(awardType2(0))
awardType3 = childDoc.GetItemValue("AwardType_3")
tawardType3 = CStr(awardType3(0))
awardType4 = childDoc.GetItemValue("AwardType_4")
tawardType4 = CStr(awardType4(0))
awardType5 = childDoc.GetItemValue("AwardType_5")
tawardType5 = CStr(awardType5(0))
awardType6 = childDoc.GetItemValue("AwardType_6")
tawardType6 = CStr(awardType6(0))
awardType7 = childDoc.GetItemValue("AwardType_7")
tawardType7 = CStr(awardType7(0))
awardType8 = childDoc.GetItemValue("AwardType_8")
tawardType8 = CStr(awardType8(0))
awardType9 = childDoc.GetItemValue("AwardType_9")
tawardType9 = CStr(awardType9(0))
awardType10 = childDoc.GetItemValue("AwardType_10")
tawardType10 = CStr(awardType10(0))
awardType11 = childDoc.GetItemValue("AwardType_11")
tawardType11 = CStr(awardType11(0))
awardType12 = childDoc.GetItemValue("AwardType_12")
tawardType12 = CStr(awardType12(0))
awardType13 = childDoc.GetItemValue("AwardType_13")
tawardType13 = CStr(awardType13(0))
awardType14 = childDoc.GetItemValue("AwardType_14")
tawardType14 = CStr(awardType14(0))
awardType15 = childDoc.GetItemValue("AwardType_15")
tawardType15 = CStr(awardType15(0))
awardType16 = childDoc.GetItemValue("AwardType_16")
tawardType16 = CStr(awardType16(0))
awardType17 = childDoc.GetItemValue("AwardType_17")
tawardType17 = CStr(awardType17(0))
awardType18 = childDoc.GetItemValue("AwardType_18")
tawardType18 = CStr(awardType18(0))
awardType19 = childDoc.GetItemValue("AwardType_19")
tawardType19 = CStr(awardType19(0))
awardType20 = childDoc.GetItemValue("AwardType_20")
tawardType20 = CStr(awardType20(0))
awardType21 = childDoc.GetItemValue("AwardType_21")
tawardType21 = CStr(awardType21(0))
awardType22 = childDoc.GetItemValue("AwardType_22")
tawardType22 = CStr(awardType22(0))
awardType23 = childDoc.GetItemValue("AwardType_23")
tawardType23 = CStr(awardType23(0))
awardType24 = childDoc.GetItemValue("AwardType_24")
tawardType24 = CStr(awardType24(0))
awardType25 = childDoc.GetItemValue("AwardType_25")
tawardType25 = CStr(awardType25(0))
allAwards = tawardType1 + " " + tawardYear1 + " " + tawardType2 + " " + tawardYear2 + " " + tawardType3 + " " + tawardYear3 + " " + _
tawardType4 + " " + tawardYear4 + " " + tawardType5 + " " + tawardYear5 + " " + tawardType6 + " " + tawardYear6 + " " + _
tawardType7 + " " + tawardYear7 + " " + tawardType8 + " " + tawardYear8 + " " + tawardType9 + " " + tawardYear9 + " " + _
tawardType10 + " " + tawardYear10 + " " + tawardType11 + " " + tawardYear11 + " " + tawardType12 + " " + tawardYear12 + " " + _
tawardType13 + " " + tawardYear13 + " " + tawardType14 + " " + tawardYear14 + " " + tawardType15 + " " + tawardType16 + " " + _
tawardType17 + " " + tawardYear17 + " " + tawardType18 + " " + tawardYear18 + " " + tawardType19 + " " + tawardYear19 + " " + _
tawardType20 + " " + tawardYear20 + " " + tawardType21 + " " + tawardYear21 + " " + tawardType22 + " " + tawardYear22 + " " + _
tawardType23 + " " + tawardYear23 + " " + tawardType24 + " " + tawardYear24 + " " + tawardType25 + " " +tawardYear25
End If
If childDoc.Form(0) = "Disciplinary Actions" Then
'Disciplinary Date Fields
DiscDate1 = childDoc.GetItemValue("DiscDate_1")
tDiscDate1 = CStr(DiscDate1(0))
DiscDate2 = childDoc.GetItemValue("DiscDate_2")
tDiscDate2 = CStr(DiscDate2(0))
DiscDate3 = childDoc.GetItemValue("DiscDate_3")
tDiscDate3 = CStr(DiscDate3(0))
DiscDate4 = childDoc.GetItemValue("DiscDate_4")
tDiscDate4 = CStr(DiscDate4(0))
DiscDate5 = childDoc.GetItemValue("DiscDate_5")
tDiscDate5 = CStr(DiscDate5(0))
DiscDate6 = childDoc.GetItemValue("DiscDate_6")
tDiscDate6 = CStr(DiscDate6(0))
DiscDate7 = childDoc.GetItemValue("DiscDate_7")
tDiscDate7 = CStr(DiscDate7(0))
DiscDate8 = childDoc.GetItemValue("DiscDate_8")
tDiscDate8 = CStr(DiscDate8(0))
DiscDate9 = childDoc.GetItemValue("DiscDate_9")
tDiscDate9 = CStr(DiscDate9(0))
DiscDate10 = childDoc.GetItemValue("DiscDate_10")
tDiscDate10 = CStr(DiscDate10(0))
DiscDate11 = childDoc.GetItemValue("DiscDate_11")
tDiscDate11 = CStr(DiscDate11(0))
DiscDate12 = childDoc.GetItemValue("DiscDate_12")
tDiscDate12 = CStr(DiscDate12(0))
DiscDate13 = childDoc.GetItemValue("DiscDate_13")
tDiscDate13 = CStr(DiscDate13(0))
DiscDate14 = childDoc.GetItemValue("DiscDate_14")
tDiscDate14 = CStr(DiscDate14(0))
DiscDate15 = childDoc.GetItemValue("DiscDate_15")
tDiscDate15 = CStr(DiscDate15(0))
DiscDate16 = childDoc.GetItemValue("DiscDate_16")
tDiscDate16 = CStr(DiscDate16(0))
DiscDate17 = childDoc.GetItemValue("DiscDate_17")
tDiscDate17 = CStr(DiscDate17(0))
DiscDate18 = childDoc.GetItemValue("DiscDate_18")
tDiscDate18 = CStr(DiscDate18(0))
DiscDate19 = childDoc.GetItemValue("DiscDate_19")
tDiscDate19 = CStr(DiscDate19(0))
DiscDate20 = childDoc.GetItemValue("DiscDate_20")
tDiscDate20 = CStr(DiscDate20(0))
DiscDate21 = childDoc.GetItemValue("DiscDate_21")
tDiscDate21 = CStr(DiscDate21(0))
DiscDate22 = childDoc.GetItemValue("DiscDate_22")
tDiscDate22 = CStr(DiscDate22(0))
DiscDate23 = childDoc.GetItemValue("DiscDate_23")
tDiscDate23 = CStr(DiscDate23(0))
DiscDate24 = childDoc.GetItemValue("DiscDate_24")
tDiscDate24 = CStr(DiscDate24(0))
DiscDate25 = childDoc.GetItemValue("DiscDate_25")
tDiscDate25 = CStr(DiscDate25(0))
'Disciplinary Charge Fields
DiscCharge1 = childDoc.GetItemValue("DiscCharge_1")
tDiscCharge1 = CStr(DiscCharge1(0))
DiscCharge2 = childDoc.GetItemValue("DiscCharge_2")
tDiscCharge2 = CStr(DiscCharge2(0))
DiscCharge3 = childDoc.GetItemValue("DiscCharge_3")
tDiscCharge3 = CStr(DiscCharge3(0))
DiscCharge4 = childDoc.GetItemValue("DiscCharge_4")
tDiscCharge4 = CStr(DiscCharge4(0))
DiscCharge5 = childDoc.GetItemValue("DiscCharge_5")
tDiscCharge5 = CStr(DiscCharge5(0))
DiscCharge6 = childDoc.GetItemValue("DiscCharge_6")
tDiscCharge6 = CStr(DiscCharge6(0))
DiscCharge7 = childDoc.GetItemValue("DiscCharge_7")
tDiscCharge7 = CStr(DiscCharge7(0))
DiscCharge8 = childDoc.GetItemValue("DiscCharge_8")
tDiscCharge8 = CStr(DiscCharge8(0))
DiscCharge9 = childDoc.GetItemValue("DiscCharge_9")
tDiscCharge9 = CStr(DiscCharge9(0))
DiscCharge10 = childDoc.GetItemValue("DiscCharge_10")
tDiscCharge10 = CStr(DiscCharge10(0))
DiscCharge11 = childDoc.GetItemValue("DiscCharge_11")
tDiscCharge11 = CStr(DiscCharge11(0))
DiscCharge12 = childDoc.GetItemValue("DiscCharge_12")
tDiscCharge12 = CStr(DiscCharge12(0))
DiscCharge13 = childDoc.GetItemValue("DiscCharge_13")
tDiscCharge13 = CStr(DiscCharge13(0))
DiscCharge14 = childDoc.GetItemValue("DiscCharge_14")
tDiscCharge14 = CStr(DiscCharge14(0))
DiscCharge15 = childDoc.GetItemValue("DiscCharge_15")
tDiscCharge15 = CStr(DiscCharge15(0))
DiscCharge16 = childDoc.GetItemValue("DiscCharge_16")
tDiscCharge16 = CStr(DiscCharge16(0))
DiscCharge17 = childDoc.GetItemValue("DiscCharge_17")
tDiscCharge17 = CStr(DiscCharge17(0))
DiscCharge18 = childDoc.GetItemValue("DiscCharge_18")
tDiscCharge18 = CStr(DiscCharge18(0))
DiscCharge19 = childDoc.GetItemValue("DiscCharge_19")
tDiscCharge19 = CStr(DiscCharge19(0))
DiscCharge20 = childDoc.GetItemValue("DiscCharge_20")
tDiscCharge20 = CStr(DiscCharge20(0))
DiscCharge21 = childDoc.GetItemValue("DiscCharge_21")
tDiscCharge21 = CStr(DiscCharge21(0))
DiscCharge22 = childDoc.GetItemValue("DiscCharge_22")
tDiscCharge22 = CStr(DiscCharge22(0))
DiscCharge23 = childDoc.GetItemValue("DiscCharge_23")
tDiscCharge23 = CStr(DiscCharge23(0))
DiscCharge24 = childDoc.GetItemValue("DiscCharge_24")
tDiscCharge24 = CStr(DiscCharge24(0))
DiscCharge25 = childDoc.GetItemValue("DiscCharge_25")
tDiscCharge25 = CStr(DiscCharge25(0))
'Disciplinary Disposition Fields
DiscDispo1 = childDoc.GetItemValue("DiscDispo_1")
tDiscDispo1 = CStr(DiscDispo1(0))
DiscDispo2 = childDoc.GetItemValue("DiscDispo_2")
tDiscDispo2 = CStr(DiscDispo2(0))
DiscDispo3 = childDoc.GetItemValue("DiscDispo_3")
tDiscDispo3 = CStr(DiscDispo3(0))
DiscDispo4 = childDoc.GetItemValue("DiscDispo_4")
tDiscDispo4 = CStr(DiscDispo4(0))
DiscDispo5 = childDoc.GetItemValue("DiscDispo_5")
tDiscDispo5 = CStr(DiscDispo5(0))
DiscDispo6 = childDoc.GetItemValue("DiscDispo_6")
tDiscDispo6 = CStr(DiscDispo6(0))
DiscDispo7 = childDoc.GetItemValue("DiscDispo_7")
tDiscDispo7 = CStr(DiscDispo7(0))
DiscDispo8 = childDoc.GetItemValue("DiscDispo_8")
tDiscDispo8 = CStr(DiscDispo8(0))
DiscDispo9 = childDoc.GetItemValue("DiscDispo_9")
tDiscDispo9 = CStr(DiscDispo9(0))
DiscDispo10 = childDoc.GetItemValue("DiscDispo_10")
tDiscDispo10 = CStr(DiscDispo10(0))
DiscDispo11 = childDoc.GetItemValue("DiscDispo_11")
tDiscDispo11 = CStr(DiscDispo11(0))
DiscDispo12 = childDoc.GetItemValue("DiscDispo_12")
tDiscDispo12 = CStr(DiscDispo12(0))
DiscDispo13 = childDoc.GetItemValue("DiscDispo_13")
tDiscDispo13 = CStr(DiscDispo13(0))
DiscDispo14 = childDoc.GetItemValue("DiscDispo_14")
tDiscDispo14 = CStr(DiscDispo14(0))
DiscDispo15 = childDoc.GetItemValue("DiscDispo_15")
tDiscDispo15 = CStr(DiscDispo15(0))
DiscDispo16 = childDoc.GetItemValue("DiscDispo_16")
tDiscDispo16 = CStr(DiscDispo16(0))
DiscDispo17 = childDoc.GetItemValue("DiscDispo_17")
tDiscDispo17 = CStr(DiscDispo17(0))
DiscDispo18 = childDoc.GetItemValue("DiscDispo_18")
tDiscDispo18 = CStr(DiscDispo18(0))
DiscDispo19 = childDoc.GetItemValue("DiscDispo_19")
tDiscDispo19 = CStr(DiscDispo19(0))
DiscDispo20 = childDoc.GetItemValue("DiscDispo_20")
tDiscDispo20 = CStr(DiscDispo20(0))
DiscDispo21 = childDoc.GetItemValue("DiscDispo_21")
tDiscDispo21 = CStr(DiscDispo21(0))
DiscDispo22 = childDoc.GetItemValue("DiscDispo_22")
tDiscDispo22 = CStr(DiscDispo22(0))
DiscDispo23 = childDoc.GetItemValue("DiscDispo_23")
tDiscDispo23 = CStr(DiscDispo23(0))
DiscDispo24 = childDoc.GetItemValue("DiscDispo_24")
tDiscDispo24 = CStr(DiscDispo24(0))
DiscDispo25 = childDoc.GetItemValue("DiscDispo_25")
tDiscDispo25 = CStr(DiscDispo25(0))
allDisciplinary = tDiscDate1 + "-" + tDiscCharge1 + "-" + tDiscDispo1 + " " + tDiscDate2 + "-" + tDiscCharge2 + "-" + tDiscDispo2 + " " + _
tDiscDate3 + "-" + tDiscCharge3 + "-" + tDiscDispo3 + " " + tDiscDate4 + "-" + tDiscCharge4 + "-" + tDiscDispo4 + " " + _
tDiscDate5 + "-" + tDiscCharge5 + "-" + tDiscDispo5 + " " + tDiscDate6 + "-" + tDiscCharge6 + "-" + tDiscDispo6 + " " + _
tDiscDate7 + "-" + tDiscCharge7 + "-" + tDiscDispo7 + " " + tDiscDate8 + "-" + tDiscCharge8 + "-" + tDiscDispo8 + " " + _
tDiscDate9 + "-" + tDiscCharge9 + "-" + tDiscDispo9 + " " + _
tDiscDate10 + "-" + tDiscCharge10 + "-" + tDiscDispo10 + " " + tDiscDate11 + "-" + tDiscCharge11 + "-" + tDiscDispo11 + " " + _
tDiscDate12 + "-" + tDiscCharge12 + "-" + tDiscDispo12 + " " + tDiscDate13 + "-" + tDiscCharge13 + "-" + tDiscDispo13 + " " + _
tDiscDate14 + "-" + tDiscCharge14 + "-" + tDiscDispo14 + " " + tDiscDate15 + "-" + tDiscCharge15 + "-" + tDiscDispo15 + " " + _
tDiscDate16 + "-" + tDiscCharge16 + " " + tDiscDate17 + "-" + tDiscCharge17 + " " + tDiscDate18 + "-" + tDiscCharge18 + " " + _
tDiscDate19 + "-" + tDiscCharge19 + "-" + tDiscDispo19 + " " + tDiscDate20 + "-" + tDiscCharge20 + "-" + tDiscDispo20 + " " + _
tDiscDate21 + "-" + tDiscCharge21 + "-" + tDiscDispo21 + " " + tDiscDate22 + "-" + tDiscCharge22 + "-" + tDiscDispo22 + " " + _
tDiscDate23 + "-" + tDiscCharge23 + "-" + tDiscDispo23 + " " + tDiscDate24 + "-" + tDiscCharge24 + "-" + tDiscDispo24 + " " + _
tDiscDate25 + "-" + tDiscCharge25 + "-" + tDiscDispo25
End If
Set childDoc = children.GetNextDocument(childDoc)
Loop
'Goes and gets information from LSP Training
Set dcTrain = trainView.GetAllDocumentsByKey(docKey, True)
Set trainDoc = dcTrain.GetFirstDocument
' Set trainDoc = dc.GetFirstDocument
trainView.AutoUpdate = False
Do While Not (trainDoc Is Nothing)
If (trainDoc.Form(0) = "Training Record") Then
sInstTrnOfcr = trainDoc.GetItemValue("InstTrnOfcr")
If (sInstTrnOfcr(0) = "X") Then
tInstTrnOfcr = "Field Training Officer"
Else
End If
sInstDutyOfcr = trainDoc.GetItemValue("InstDutyOfcr")
If (sInstDutyOfcr(0) = "X") Then
tInstDutyOfcr = "Duty Officer"
Else
End If
sInstTechAccInvest = trainDoc.GetItemValue("InstTechAccInvest")
If (sInstTechAccInvest(0) = "X") Then
tInstTechAccInvest = "Crash Reconstructionist"
Else
End If
sInstAccInvest = trainDoc.GetItemValue("InstAccInvest")
If (sInstAccInvest(0) = "X") Then
tInstAccInvest = "Crash Investigation Instructor"
Else
End If
sInstDefTact = trainDoc.GetItemValue("InstDefTact")
If (sInstDefTact(0) = "X") Then
tInstDefTact = "Defensive Tactics Instructor"
Else
End If
sInstPR24 = trainDoc.GetItemValue("InstPR24")
If (sInstPR24(0) = "X") Then
tInstPR24 = "PR-24 Instructor"
Else
End If
sInstSWAT = trainDoc.GetItemValue("InstSWAT")
If (sInstSWAT(0) = "X") Then
tInstSWAT = "SWAT"
Else
End If
sInstGeneral = trainDoc.GetItemValue("InstGeneral")
If (sInstGeneral(0) = "X") Then
tInstGeneral = "General Instructor"
Else
End If
sInstRangeSafetyOfcr = trainDoc.GetItemValue("InstRangeSafetyOfcr")
If (sInstRangeSafetyOfcr(0) = "X") Then
tInstRangeSafetyOfcr = "Range Safety Officer"
Else
End If
sInstFireArms = trainDoc.GetItemValue("InstFireArms")
If (sInstFireArms(0) = "X") Then
tInstFireArms = "Firearms Instructor"
Else
End If
sInstTaser = trainDoc.GetItemValue("InstTaser")
If (sInstTaser(0) = "X") Then
tInstTaser = "Taser Instructor"
Else
End If
sInstRadar = trainDoc.GetItemValue("InstRadar")
If (sInstRadar(0) = "X") Then
tInstRadar = "RADAR/LIDAR Instructor"
Else
End If
sInstFirstAid = trainDoc.GetItemValue("InstFirstAid")
If (sInstFirstAid(0) = "X") Then
tInstFirstAid = "First Aid Instructor"
Else
End If
sInstCPR = trainDoc.GetItemValue("InstCPR")
If (sInstCPR(0) = "X") Then
tInstCPR = "CPR Instructor"
Else
End If
sInstDefDriv = trainDoc.GetItemValue("InstDefDriv")
If (sInstDefDriv(0) = "X") Then
tInstDefDriv = "EVO Instructor"
Else
End If
sInstMotorcycle = trainDoc.GetItemValue("InstMotorcycle")
If (sInstMotorcycle(0) = "X") Then
tInstMotorcycle = "Motorcycle Instructor"
Else
End If
sInstChildRestraint = trainDoc.GetItemValue("InstChildRestraint")
If (sInstChildRestraint(0) = "X") Then
tInstChildRestraint = "Child Restraint Instructor"
Else
End If
sInstFldSobr = trainDoc.GetItemValue("InstFldSobr")
If (sInstFldSobr(0) = "X") Then
tInstFldSobr = "SFST Instructor"
Else
End If
sInstDrugRecExpert = trainDoc.GetItemValue("InstDrugRecExpert")
If (sInstDrugRecExpert(0) = "X") Then
tInstDrugRecExpert = "Drug Recognition Expert"
Else
End If
sInstFbiInstDevlp = trainDoc.GetItemValue("InstFbiInstDevlp")
If (sInstFbiInstDevlp(0) = "X") Then
tInstFbiInstDevlp = "FBI Instructor Development"
Else
End If
sInstFBI = trainDoc.GetItemValue("InstFBI")
If (sInstFBI(0) = "X") Then
tInstFBI = "FBI National Academy"
Else
End If
sInstNorthwestern = trainDoc.GetItemValue("InstNorthwestern")
If (sInstNorthwestern(0) = "X") Then
tInstNorthwestern = "NU School Police Staff/Command"
Else
End If
allTraining = tInstTrnOfcr + ", " + tInstDutyOfcr + ", " + tInstTechAccInvest + ", " + tInstAccInvest + ", " + _
tInstDefTact + ", " + tInstPR24 + ", " + tInstSWAT + ", " + tInstGeneral + ", " + tInstRangeSafetyOfcr + ", " + _
tInstFireArms + ", " + tInstTaser + ", " + tInstRadar + ", " + tInstFirstAid + ", " + tInstCPR + ", " + _
tInstDefDriv + ", " + tInstMotorcycle + " , " + tInstChildRestraint + ", " + tInstFldSobr + ", " + tInstDrugRecExpert + " " +_
tInstFbiInstDevlp + ", " + tInstFBI + ", " + tInstNorthwestern
End If
If (trainDoc.Form(0) = "Recertify Record") Then
vRecertify = childDoc.GetItemValue("RecertifyRequalSelection")
tRecertify = CStr(vRecertify(0))
End If
Set trainDoc = dcTrain.GetNextDocument(trainDoc)
' Set trainDoc = dc.GetNextDocument(trainDoc)
Loop
Set doc = dc.GetNextDocument(doc)
Wend
'\\\Create the Report document
End Sub
It sounds like your code (which you should post!) is working. I would suggest to add a counter for each Notes document you process, that will help you address the correct row in the spreadsheet.
I would also recommend that you learn about arrays. They are a very fundamental concept in all programming, and you pretty much have to understand it in order to be a programmer. I would also suggest that you look at lists in Lotusscript, that is a very powerful data type.
You may also want to take at this class that I posted a while back:
http://blog.texasswede.com/export-notes-view-to-excel-with-multi-value-fields/
It creates a CSV file, but it should be trivial for you to modify it to write straight to a spreadsheet in Excel. You even have a counter in that code to count the rows...
Update after code was posted
You really need to learn about arrays. That code is many times longer and more convuluted than it has to be. You also use multiple steps when one step would be sufficient.
For example:
awardYear1 = childDoc.GetItemValue("AwardYear_1")
tawardYear1 = CStr(awardYear1(0))
awardYear2 = childDoc.GetItemValue("AwardYear_2")
tawardYear2 = CStr(awardYear2(0))
etc...
First of all, you could write it as follows, to avoid using temporary variables:
awardYear1 = Cstr(childDoc.GetItemValue("AwardYear_1")(0))
But when you have 25 identical fields (which you should not have, it seems like the design of the original form is really bad as well), use an array:
Dim awardYear(24) as String
For i = 0 to 24
awardYear(i) = Cstr( childDoc.GetItemValue("AwardYear_" & i+1)(0) )
Next
Those few lines would replace 50 lines of your code to start with...
You could do that through out your code, and make it much smaller.
You could also use an array of a custom data type.
Type OfficerData
awardYear As Integer
awardType As String
discDate As NotesDateTime
discCharge As String
discDispo As String
End Type
Dim officer(24) as OfficerData
Now you can use it like this:
officer(1).awardYear = 2010
officer(1).awardType = "Pistol Champion"
Easy, huh? :-)
You should always use Option Declare. This forces you to declare any variables but also helps you, in that it will be much easier to find typos in variable names. It is a long-established best practice.
Just to show, that i WANT to help: All things, that Karl-Henry mentioned are True. But the real problem in your code is: You reassign the values for e.g. allAwards within the loop. As you run through all documents, the variable will only contain the content of the LAST document.
And here again Karl-Henry is true: You should use an array to store the values...
Dim allAwards() as String
....
Set children = doc.Responses
Redim allAwards(children.Count-1)
i = 0
....
allAwards(i) = tawardType1 + " " + tawardYear1 + " " + tawardType2 + " " + tawardYear2 + " " + tawardType3 + " " + tawardYear3 + " " + _
tawardType4 + " " + tawardYear4 + " " + tawardType5 + " " + tawardYear5 + " " + tawardType6 + " " + tawardYear6 + " " + _
tawardType7 + " " + tawardYear7 + " " + tawardType8 + " " + tawardYear8 + " " + tawardType9 + " " + tawardYear9 + " " + _
tawardType10 + " " + tawardYear10 + " " + tawardType11 + " " + tawardYear11 + " " + tawardType12 + " " + tawardYear12 + " " + _
tawardType13 + " " + tawardYear13 + " " + tawardType14 + " " + tawardYear14 + " " + tawardType15 + " " + tawardType16 + " " + _
tawardType17 + " " + tawardYear17 + " " + tawardType18 + " " + tawardYear18 + " " + tawardType19 + " " + tawardYear19 + " " + _
tawardType20 + " " + tawardYear20 + " " + tawardType21 + " " + tawardYear21 + " " + tawardType22 + " " + tawardYear22 + " " + _
tawardType23 + " " + tawardYear23 + " " + tawardType24 + " " + tawardYear24 + " " + tawardType25 + " " +tawardYear25
i = i + 1
Like that you have ALL values of ALL documents in your Variable allAwards and can later cycle through this array to write each value into the excel- file.

Write Queries on Excel sheet in c#

I want to update specific row of excel sheet from my asp.net application. I m able to read excel, but how can i update the records.Can i write Update query . How . please send me code:
string strQuery = "UPDATE [Sheet1$] SET Child Name=" + "\"" + strDataToUpdate[0] + "\",";
strQuery = strQuery + "Pickup Point Name=" + "\"" + strDataToUpdate[1] + "\",";
strQuery = strQuery + "Pickup Bus No=" + "\"" + strDataToUpdate[2] + "\",";
strQuery = strQuery + "Pickup Bus Time=" + "\"" + strDataToUpdate[3] + "\",";
strQuery = strQuery + "Drop Down Point Name=" + "\"" + strDataToUpdate[4] + "\",";
strQuery = strQuery + "Drop Bus No=" + "\"" + strDataToUpdate[5] + "\",";
strQuery = strQuery + "Drop Down Bus Time=" + "\"" + strDataToUpdate[6] + "\",";
strQuery = strQuery + "Parent Name=" + "\"" + strDataToUpdate[7] + "\",";
strQuery = strQuery + "Mobile 1=" + "\"" + strDataToUpdate[8] + "\",";
strQuery = strQuery + "Mobile 2=" + "\"" + strDataToUpdate[9] + "\",";
strQuery = strQuery + "Email ID 1=" + "\"" + strDataToUpdate[10] + "\",";
strQuery = strQuery + "Email ID 2=" + "\"" + strDataToUpdate[11] + "\",";
strQuery = strQuery + "Service Mode=" + "\"" + strDataToUpdate[12] + "\",";
strQuery = strQuery + "WHERE Child Id=" + strDataToUpdate[13];
This Query i am using giving Syntax error.Please guide
you can use it through ADO.NET. This is explained here
SpreadsheetGear for .NET can do it.
You can see live ASP.NET samples with C# and VB source code here and download the free trial here if you want to try it yourself.
Disclaimer: I own SpreadsheetGear LLC
when your field name consist space, you must put filed name in brakets for example:
string strQuery = "UPDATE [Sheet1$] SET [Child Name]=" + "\"" + strDataToUpdate[0] + "\",";

Resources