J
Jen
Hi.
I found this cool free word template using a vba macro to print out a bank
barcode on an invoice; (
http://www.iki.fi/~dm/products/barcodelib/index.html ). The macro collects
data from numbers stored as bookmarks in the word document. The word macro
is shown further down below.
My question is, how do I have to change this macro to be able to collect the
values from textboxes from an access report (named invoicereport), lets say:
txt_total=amount
txt_account=accountnumber
txt_reference=referencenumber
txt_due=duedate
txt_barcode= Here the macro would write the barcode.
Have banged my head against the wall for couple of ewenings now, finally
realising I won't get this to work without help.
The word macro:
Sub CreateBarCode()
Dim amount As Double
amount = CDbl(ActiveDocument.Bookmarks("Amount").Range.Text)
Rem In this version, the currency is hard-coded as EUR.
Dim currenc As String
currenc = "EUR"
Dim account As String
account = Trim(ActiveDocument.Bookmarks("AccountNumber").Range.Text)
Dim reference As String
reference = Trim(ActiveDocument.Bookmarks("BankReference").Range.Text)
Dim duedateStr As String
duedateStr = ActiveDocument.Bookmarks("DueDate").Range.Text
Dim duedate As Date, tmdate As tm
'This would use system locale:
'duedate = CDate(duedateStr)
'But instead we use the fixed format 'd.m.yyyy'
Dim dateparts As Variant
dateparts = Split(duedateStr, ".")
duedate = DateSerial(Val(dateparts(2)), Val(dateparts(1)),
Val(dateparts(0)))
tmdate = AsTMDate(year(duedate), month(duedate), day(duedate))
Dim handle As Long
handle = BCL_Invoice_create(0)
Dim resLONG As Long, res As String
resLONG = BCL_Invoice_convert(handle, amount, currenc, account, reference,
tmdate)
res = BCL_convertStringToBSTR(resLONG, -1)
If res <> "" Then
ActiveDocument.Bookmarks("BarCode").Select
Dim fontLONG As Long, font As String
fontLONG = BCL_getFont(handle)
font = BCL_convertStringToBSTR(fontLONG, -1)
Dim fontSize As Integer
fontSize = BCL_getHeight(handle, 11.3)
Selection.font.Name = font
Selection.font.Size = fontSize
Selection.Text = res
ActiveDocument.Bookmarks.Add Name:="BarCode", Range:=Selection.Range
Else
Dim errLONG As Long, err As String
errLONG = BCL_getError(handle)
err = BCL_convertStringToBSTR(errLONG, -1)
MsgBox ("Error = " + err)
End If
BCL_release (handle)
End Sub
I found this cool free word template using a vba macro to print out a bank
barcode on an invoice; (
http://www.iki.fi/~dm/products/barcodelib/index.html ). The macro collects
data from numbers stored as bookmarks in the word document. The word macro
is shown further down below.
My question is, how do I have to change this macro to be able to collect the
values from textboxes from an access report (named invoicereport), lets say:
txt_total=amount
txt_account=accountnumber
txt_reference=referencenumber
txt_due=duedate
txt_barcode= Here the macro would write the barcode.
Have banged my head against the wall for couple of ewenings now, finally
realising I won't get this to work without help.
The word macro:
Sub CreateBarCode()
Dim amount As Double
amount = CDbl(ActiveDocument.Bookmarks("Amount").Range.Text)
Rem In this version, the currency is hard-coded as EUR.
Dim currenc As String
currenc = "EUR"
Dim account As String
account = Trim(ActiveDocument.Bookmarks("AccountNumber").Range.Text)
Dim reference As String
reference = Trim(ActiveDocument.Bookmarks("BankReference").Range.Text)
Dim duedateStr As String
duedateStr = ActiveDocument.Bookmarks("DueDate").Range.Text
Dim duedate As Date, tmdate As tm
'This would use system locale:
'duedate = CDate(duedateStr)
'But instead we use the fixed format 'd.m.yyyy'
Dim dateparts As Variant
dateparts = Split(duedateStr, ".")
duedate = DateSerial(Val(dateparts(2)), Val(dateparts(1)),
Val(dateparts(0)))
tmdate = AsTMDate(year(duedate), month(duedate), day(duedate))
Dim handle As Long
handle = BCL_Invoice_create(0)
Dim resLONG As Long, res As String
resLONG = BCL_Invoice_convert(handle, amount, currenc, account, reference,
tmdate)
res = BCL_convertStringToBSTR(resLONG, -1)
If res <> "" Then
ActiveDocument.Bookmarks("BarCode").Select
Dim fontLONG As Long, font As String
fontLONG = BCL_getFont(handle)
font = BCL_convertStringToBSTR(fontLONG, -1)
Dim fontSize As Integer
fontSize = BCL_getHeight(handle, 11.3)
Selection.font.Name = font
Selection.font.Size = fontSize
Selection.Text = res
ActiveDocument.Bookmarks.Add Name:="BarCode", Range:=Selection.Range
Else
Dim errLONG As Long, err As String
errLONG = BCL_getError(handle)
err = BCL_convertStringToBSTR(errLONG, -1)
MsgBox ("Error = " + err)
End If
BCL_release (handle)
End Sub