Hi Guys,
the project im currently creating is a basic form with calculations, which all works great, my task now is to save the form data (labels, textbox data etc) to a word document, now i have achieved it to do this, but i had to specify the name of the word doc (as code shows below) does anyone know how i can get the save button to pick up on a certain bite of data of the form (lets pick the date) and save the word document to the date name (i.e 12.12.2012) instead of what i have put (invoice.doc) i have posted all of the code except the calculations (as they are not important for this task)
many thanks for taking a look guys :)
p.s i know there is alot of objwriter code, but i didnt know how else to pull to data from the textboxes etc and write them elsewhere (in this case word doc)
Private Sub cmd_Save_Click(sender As System.Object, e As System.EventArgs) Handles cmd_Save.Click
'****************************************************************************************'
'Creating variables for a new Word Document to save the form data including the file path'
'****************************************************************************************'
Dim New_Doc As String = "C:\Users\ComputerFirstAde\Desktop\Invoice.doc"
Dim ObjWriter As New System.IO.StreamWriter(New_Doc)
'*********************************************************************************************'
'Pulling out the data from all the labels and textboxes reading to go to the new word document'
'*********************************************************************************************'
ObjWriter.Write(" ")
ObjWriter.Write(lbl_Invoice_Heading.Text)
ObjWriter.WriteLine()
ObjWriter.WriteLine()
ObjWriter.WriteLine()
ObjWriter.Write(lbl_invoice_number.Text)
ObjWriter.Write(" : ")
ObjWriter.Write(tbox_Inv_Number.Text)
ObjWriter.Write(" ")
ObjWriter.Write(lbl_Invoice_Date.Text)
ObjWriter.Write(" : ")
ObjWriter.Write(tbox_Inv_Date.Text)
ObjWriter.WriteLine()
ObjWriter.WriteLine()
ObjWriter.Write(lbl_Comp_Name.Text)
ObjWriter.Write(" : ")
ObjWriter.Write(tbox_Comp_Name.Text)
ObjWriter.WriteLine()
ObjWriter.WriteLine()
ObjWriter.Write(lbl_Add_Line_1.Text)
ObjWriter.Write(" : ")
ObjWriter.Write(tbox_Add_Line1.Text)
ObjWriter.WriteLine()
ObjWriter.WriteLine()
ObjWriter.Write(lbl_Add_Line_2.Text)
ObjWriter.Write(" : ")
ObjWriter.Write(tbox_Add_Line2.Text)
ObjWriter.WriteLine()
ObjWriter.WriteLine()
ObjWriter.WriteLine()
ObjWriter.Write(lbl_Type.Text)
ObjWriter.Write(" ")
ObjWriter.Write(lbl_Quantity.Text)
ObjWriter.Write(" ")
ObjWriter.Write(lbl_Price.Text)
ObjWriter.Write(" ")
ObjWriter.Write(lbl_Totals.Text)
ObjWriter.WriteLine()
ObjWriter.WriteLine()
ObjWriter.Write(lbl_15.Text)
ObjWriter.Write(" ")
ObjWriter.Write(tbox_Qty_15.Text)
ObjWriter.Write(" ")
ObjWriter.Write(tbox_Price_15.Text)
ObjWriter.Write(" ")
ObjWriter.Write(tbox_Total_15.Text)
ObjWriter.WriteLine()
ObjWriter.WriteLine()
ObjWriter.Write(lbl_17.Text)
ObjWriter.Write(" ")
ObjWriter.Write(tbox_Qty_17.Text)
ObjWriter.Write(" ")
ObjWriter.Write(tbox_Price_17.Text)
ObjWriter.Write(" ")
ObjWriter.Write(tbox_Total_17.Text)
ObjWriter.WriteLine()
ObjWriter.WriteLine()
ObjWriter.Write(lbl_19.Text)
ObjWriter.Write(" ")
ObjWriter.Write(tbox_Qty_19.Text)
ObjWriter.Write(" ")
ObjWriter.Write(tbox_Price_19.Text)
ObjWriter.Write(" ")
ObjWriter.Write(tbox_Total_19.Text)
ObjWriter.WriteLine()
ObjWriter.WriteLine()
ObjWriter.Write(" ")
ObjWriter.Write(lbl_SubTotal.Text)
ObjWriter.Write(" ")
ObjWriter.Write(tbox_SubTotal.Text)
ObjWriter.WriteLine()
ObjWriter.WriteLine()
ObjWriter.Write(" ")
ObjWriter.Write(lbl_Tax.Text)
ObjWriter.Write(" ")
ObjWriter.Write(tbox_Total_Tax.Text)
ObjWriter.WriteLine()
ObjWriter.WriteLine()
ObjWriter.Write(" ")
ObjWriter.Write(tbox_Grand_Total.Text)
ObjWriter.Close()
'******************************'
'creating the new word document'
'******************************'
If Not System.IO.File.Exists(New_Doc) Then
System.IO.File.Create(New_Doc).Dispose()
End If
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'**************************************************************************************'
'Setting the date to automatically pull out todays date and send it to the invoice date'
'**************************************************************************************'
tbox_Inv_Date.Text = DateValue(Now)
End Sub