Hi,
When I click a button I have a MS Word doc to open.
The first time when the program runs, I click, it just does some process but does not open the doc, but on the next clicks it works.
How to make the Word doc, open when I click the first time.
Printable View
Hi,
When I click a button I have a MS Word doc to open.
The first time when the program runs, I click, it just does some process but does not open the doc, but on the next clicks it works.
How to make the Word doc, open when I click the first time.
Where is the code that you are using?
VB Code:
Private Sub printpo_Click() Dim i, j, n, s, r, c Dim count1, qid Dim response As Integer Dim msg, select_statement Dim myrange Dim oPara1 As Word.Paragraph, oPara2 As Word.Paragraph 'Writing to word doc for Purchase Order Set oApp = New Word.Application Dim oTable As Word.Table Set oDoc = oApp.Documents.Open("C:\Pax Spices\Order Entry\PO.doc") oDoc.Select 'oApp.ActiveDocument.Paragraphs(2).Range.Start oApp.Selection.Font.Name = "Times New Roman" oApp.Selection.Font.Size = "24" oApp.Selection.Font.Color = wdColorBlue oApp.Selection.TypeParagraph oApp.Selection.TypeParagraph oApp.Selection.Font.Name = "Times New Roman" oApp.Selection.Font.Size = "12" oApp.Selection.Font.Color = wdColorBlack oApp.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter oApp.Selection.Font.Bold = wdToggle oApp.Selection.Font.Underline = wdUnderlineSingle oApp.Selection.TypeText Text:="Purchase Order" oApp.Selection.Font.Underline = wdUnderlineNone oApp.Selection.Font.Bold = wdToggle oApp.Selection.TypeParagraph oApp.Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft oApp.Selection.Font.Bold = wdToggle oApp.Selection.TypeText Text:="Purchase Order#: " oApp.Selection.Font.Bold = wdToggle oApp.Selection.TypeText Text:=pono.Text oApp.Selection.TypeText Text:=vbTab & vbTab & vbTab oApp.Selection.Font.Bold = wdToggle oApp.Selection.TypeText Text:="Date of Purchase Order " oApp.Selection.Font.Bold = wdToggle oApp.Selection.TypeText Text:=podate.Text oApp.Selection.TypeParagraph oApp.Selection.TypeParagraph oApp.Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft oApp.Selection.Font.Bold = wdToggle oApp.Selection.TypeText Text:="Supplier Name: " oApp.Selection.Font.Bold = wdToggle oApp.Selection.TypeParagraph oApp.Selection.TypeText Text:=suppname.Text select_statement = "select * from supplier where suppname='" & suppname.Text & "' " qry (select_statement) oApp.Selection.TypeParagraph oApp.Selection.TypeText Text:="" & rs!Address oApp.Selection.TypeParagraph oApp.Selection.TypeText Text:="" & rs!City oApp.Selection.TypeParagraph oApp.Selection.TypeText Text:="" & rs!state oApp.Selection.TypeParagraph oApp.Selection.TypeText Text:="" & rs!zip oApp.Selection.TypeParagraph oApp.Selection.TypeText Text:="" & rs!country oApp.Selection.TypeParagraph oApp.Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft oApp.Selection.TypeParagraph oApp.Selection.Font.Bold = wdToggle oApp.Selection.TypeText Text:="Bill To: " oApp.Selection.TypeText Text:=vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab oApp.Selection.TypeText Text:="Ship To: " oApp.Selection.TypeParagraph oApp.Selection.Font.Bold = wdToggle oApp.Selection.TypeText Text:=billtoname.Text 'oApp.Selection.TypeText Text:=" " oApp.Selection.TypeText Text:=vbTab & vbTab & vbTab & vbTab & vbTab oApp.Selection.TypeText Text:=custname.Text oApp.Selection.TypeParagraph oApp.Selection.TypeText Text:=billtoadd.Text 'oApp.Selection.TypeText Text:=" " oApp.Selection.TypeText Text:=vbTab & vbTab & vbTab & vbTab & vbTab & vbTab oApp.Selection.TypeText Text:=shiptoadd.Text oApp.Selection.TypeParagraph oApp.Selection.TypeText Text:=billtocity.Text ' oApp.Selection.TypeText Text:=" " oApp.Selection.TypeText Text:=vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab oApp.Selection.TypeText Text:=city1.Text oApp.Selection.TypeParagraph oApp.Selection.TypeText Text:=billtostate.Text 'oApp.Selection.TypeText Text:=" " oApp.Selection.TypeText Text:=vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab oApp.Selection.TypeText Text:=state.Text oApp.Selection.TypeParagraph oApp.Selection.TypeText Text:=billtocountry.Text 'oApp.Selection.TypeText Text:=" " oApp.Selection.TypeText Text:=vbTab & vbTab & vbTab & vbTab & vbTab & vbTab & vbTab oApp.Selection.TypeText Text:=country.Text oApp.Selection.TypeParagraph oApp.Selection.Font.Bold = wdToggle oApp.Selection.TypeText Text:="Phone " oApp.Selection.Font.Bold = wdToggle oApp.Selection.TypeText Text:=billtoph.Text 'oApp.Selection.TypeText Text:=" " oApp.Selection.TypeText Text:=vbTab & vbTab & vbTab & vbTab & vbTab & vbTab oApp.Selection.TypeText Text:=phone.Text oApp.Selection.TypeParagraph oApp.Selection.TypeParagraph oApp.Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft oApp.Selection.Font.Bold = wdToggle oApp.Selection.Font.Underline = wdUnderlineSingle oApp.Selection.TypeText Text:="REQ BY" oApp.Selection.Font.Underline = wdUnderlineNone oApp.Selection.TypeText Text:=vbTab oApp.Selection.Font.Underline = wdUnderlineSingle oApp.Selection.TypeText Text:="SHIP WHEN" oApp.Selection.Font.Underline = wdUnderlineNone oApp.Selection.TypeText Text:=vbTab & vbTab oApp.Selection.Font.Underline = wdUnderlineSingle oApp.Selection.TypeText Text:="SHIP VIA " oApp.Selection.Font.Underline = wdUnderlineNone oApp.Selection.TypeText Text:=vbTab oApp.Selection.Font.Underline = wdUnderlineSingle oApp.Selection.TypeText Text:="PICK UP" oApp.Selection.Font.Underline = wdUnderlineNone oApp.Selection.TypeText Text:=vbTab oApp.Selection.Font.Underline = wdUnderlineNone oApp.Selection.Font.Underline = wdUnderlineSingle oApp.Selection.TypeText Text:="TERMS " oApp.Selection.Font.Underline = wdUnderlineNone oApp.Selection.TypeText Text:=vbTab oApp.Selection.Font.Underline = wdUnderlineNone oApp.Selection.Font.Underline = wdUnderlineSingle oApp.Selection.TypeText Text:="FOB" oApp.Selection.Font.Underline = wdUnderlineNone oApp.Selection.TypeText Text:=vbTab oApp.Selection.Font.Bold = wdToggle oApp.Selection.TypeParagraph oApp.Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft oApp.Selection.TypeText Text:=reqby.Text oApp.Selection.TypeText Text:=vbTab & vbTab oApp.Selection.TypeText Text:=shipwhen.Text oApp.Selection.TypeText Text:=vbTab & vbTab & vbTab oApp.Selection.TypeText Text:=shipvia.Text oApp.Selection.TypeText Text:=vbTab oApp.Selection.TypeText Text:=pickupdate.Text oApp.Selection.TypeText Text:=vbTab oApp.Selection.TypeText Text:=terms.Text oApp.Selection.TypeText Text:=vbTab oApp.Selection.TypeText Text:=fob.Text oApp.Selection.TypeParagraph oApp.Selection.TypeParagraph oApp.Selection.TypeParagraph oApp.Selection.Font.Bold = wdToggle oApp.Selection.TypeText Text:="Remarks " oApp.Selection.TypeParagraph oApp.Selection.Font.Bold = wdToggle oApp.Selection.TypeText Text:=remarks.Text oApp.Selection.TypeParagraph oApp.Selection.TypeParagraph oApp.Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft oApp.Selection.Font.Bold = wdToggle oApp.Selection.TypeText Text:="Item" oApp.Selection.TypeText Text:=vbTab & vbTab & vbTab oApp.Selection.TypeText Text:="Description" oApp.Selection.TypeText Text:=vbTab & vbTab oApp.Selection.TypeText Text:="Quantity" oApp.Selection.TypeText Text:=vbTab & vbTab oApp.Selection.TypeText Text:="Rate/lb " oApp.Selection.TypeText Text:=vbTab oApp.Selection.TypeText Text:="Total" oApp.Selection.TypeText Text:=vbTab oApp.Selection.Font.Bold = wdToggle select_statement = "select itemno,proddesc,qty,ratelb,total from podetails where pono='" & pono.Text & "';" qry (select_statement) count1 = rs.RecordCount If count1 <> 0 Then Set myrange = oApp.ActiveDocument.Range(Start:=oApp.Selection.Start, End:=oApp.Selection.End) Set oTable = oDoc.Tables.add(myrange, count1, 5) oTable.Range.ParagraphFormat.SpaceAfter = 6 End Sub
oApp.Visible = True.