PDA

View Full Version : Order Form



awalker
08-19-2015, 06:02 AM
Hi Clever people
I was wondering if you could help, I currently have a standing order form (attached)14213 I would like to take some of the manual input out of it, I want to have an input box were they can select the frequency of the order e.g every monday, every week, fortnightly etc then input a start date and have the dates populate the place order on box.
I hope this makes sense.
Thanks
Andrew

gmayor
08-20-2015, 10:57 PM
You could create a userform - http://www.gmayor.com/Userform.htm to gather the information and write it to the next available cells of the table. To facilitate that split the second table above the orange title row, as tables with merged cells are a pain to process. You can then call the following sub FillTable to fill the table with the three pieces of data from your userform in the next available cells.

You can test the sub by running macro 1, but do split the tables first!


Option Explicit
Sub Macro1()
FillTable "A", "B", "C"
End Sub

Sub FillTable(strA As String, strB As String, strC As String)
Dim oTable As Table
Dim i As Long, j As Long
Dim oCell As Range, oRng1 As Range
Dim oRng2 As Range, oRng3 As Range
Dim NextCell As Long

Set oTable = ActiveDocument.Tables(3)
Set oCell = oTable.Rows(oTable.Rows.Count).Cells(4).Range
oCell.End = oCell.End - 1
If Len(oCell) > 0 Then
MsgBox "Table is full!"
GoTo lbl_Exit
End If

Set oCell = oTable.Rows(oTable.Rows.Count).Cells(1).Range
oCell.End = oCell.End - 1

If Len(oCell) > 0 Then
NextCell = 4
Else
NextCell = 1
End If

For i = 2 To oTable.Rows.Count
Set oCell = oTable.Rows(i).Cells(NextCell).Range
oCell.End = oCell.End - 1
If Len(oCell) = 0 Then
Set oRng1 = oCell
Set oRng2 = oCell.Next
oRng2.End = oRng2.End - 1
Set oRng3 = oRng2.Next
oRng3.End = oRng3.End - 1
Exit For
End If
Next i
oRng1.Text = strA
oRng2.Text = strB
oRng3.Text = strC
lbl_Exit:
Set oTable = Nothing
Set oCell = Nothing
Set oRng1 = Nothing
Set oRng2 = Nothing
Set oRng3 = Nothing
Exit Sub
End Sub

gmayor
08-21-2015, 01:18 AM
It is far too hot outside this morning to do anything useful, so I have been amusing myself with your document to pass a lazy hour. I have added a userform and the above process and it will perform the selected number of repeats with the interval specified. You can add to or change the form to produce the results you require, but this should set you on your way. To evaluate, create a new document from the template.