Hi all!
I have a problem with a word document.
I have Built a invoice template for a customer. My tought is that when he press a button, after he has filled the invoice, a vb function is called. The fuction will go to a pree defined mapPath. It will lopp all the wordfiles and select the max filenameNumber. All the files is named with i number. Then it will add 1 to that number. Then it will save and name the new invoice with the new number.
Here is the code:
Private Sub cmdSaveDok_Click()
Dim newName As String
Dim maxVal As Integer
Dim dirVal As Integer
Dim pStr As String
Dim nVal As Integer
Dim MyPath As String
Dim MyName As String
'MyPath = "\\JOHAN\Takman Dokument\Fakturor\"
MyPath = "C:\Temp\"
maxVal = 0
MyName = Dir(MyPath, vbNormal)
'Kör loopen
Do While MyName <> ""
If MyName <> "." And MyName <> ".." Then
If (GetAttr(MyPath & MyName) And vbNormal) = vbNormal Then
'Sorterar ut siffrorna i filnamnet och sparar undan dem
If IsNumeric(Left(MyName, Len(MyName) - 4)) Then
dirVal = CInt(Left(MyName, Len(MyName) - 4))
If dirVal > maxVal Then maxVal = dirVal
End If
End If
End If
MyName = Dir
Loop
'Plussar på ett
If maxVal = 0 Then
nVal = 10000
Else
nVal = maxVal + 1
End If
'Sparar dokumentet
newName = MyPath & CStr(nVal) & ".doc"
ThisDocument.TextBox1.Text = CStr(nVal)
ThisDocument.SaveAs newName
MsgBox ("Dokument " & newName & " är sparat.")
End Sub
My problem is:
The code works just fine excepts that the ThisDocument.TextBox1.Text dose not show the new number and when a quit the template. the new max number is not saved in the template. SO that next time my customer open the template he will se tha last used invioce number.
How do i do that?
Do u follow me? if not i will try to explane it better
/Tyronne
I have a problem with a word document.
I have Built a invoice template for a customer. My tought is that when he press a button, after he has filled the invoice, a vb function is called. The fuction will go to a pree defined mapPath. It will lopp all the wordfiles and select the max filenameNumber. All the files is named with i number. Then it will add 1 to that number. Then it will save and name the new invoice with the new number.
Here is the code:
Private Sub cmdSaveDok_Click()
Dim newName As String
Dim maxVal As Integer
Dim dirVal As Integer
Dim pStr As String
Dim nVal As Integer
Dim MyPath As String
Dim MyName As String
'MyPath = "\\JOHAN\Takman Dokument\Fakturor\"
MyPath = "C:\Temp\"
maxVal = 0
MyName = Dir(MyPath, vbNormal)
'Kör loopen
Do While MyName <> ""
If MyName <> "." And MyName <> ".." Then
If (GetAttr(MyPath & MyName) And vbNormal) = vbNormal Then
'Sorterar ut siffrorna i filnamnet och sparar undan dem
If IsNumeric(Left(MyName, Len(MyName) - 4)) Then
dirVal = CInt(Left(MyName, Len(MyName) - 4))
If dirVal > maxVal Then maxVal = dirVal
End If
End If
End If
MyName = Dir
Loop
'Plussar på ett
If maxVal = 0 Then
nVal = 10000
Else
nVal = maxVal + 1
End If
'Sparar dokumentet
newName = MyPath & CStr(nVal) & ".doc"
ThisDocument.TextBox1.Text = CStr(nVal)
ThisDocument.SaveAs newName
MsgBox ("Dokument " & newName & " är sparat.")
End Sub
My problem is:
The code works just fine excepts that the ThisDocument.TextBox1.Text dose not show the new number and when a quit the template. the new max number is not saved in the template. SO that next time my customer open the template he will se tha last used invioce number.
How do i do that?
Do u follow me? if not i will try to explane it better
/Tyronne