Run time error 438: (wks.cells(i, 1)) - stored-procedures

I am attempting to paste information from a spreadsheet to a form in my Access database but I get an error at the Do Until IsEmpty(wks.Cells(i, 1)) line. I am using Access 2010.
Option Compare Database
Private Sub Cmd_Mass_Upload_Click()
If MsgBox("ARE YOU SURE YOU WANT TO UPDATE RECORDS?", vbOKCancel, "CONFIRM MASS UPDATE") = vbOK Then
Dim wks
Dim db As Database
Dim rsCheckDuplicate As Recordset
Dim rsUpdateCC As Recordset
Dim strSQLCheckDuplicate As String
Dim strUpdateCC As String
Dim succesfullyUpdated As Integer
succesfullyUpdated = 0
i = 1
'If Me.Ctl2003 = True Then
Set wks = Me.upLoadSpreadsheet2010
'End If
'If Me.Ctl2010 = True Then
' Set wks = Me.upLoadSpreadsheet2010
'End If
Do Until IsEmpty(wks.Cells(i, 1))
i = i + 1
Loop
Set db = CurrentDb
If i > 1 Then
For j = 1 To i - 1
strSQLCheckDuplicate = "SELECT TBL_OPEN_VOUCHERS.[VOUCHER NUMBER], TBL_OPEN_VOUCHERS.[INVOICE NUMBER] " & _
"FROM TBL_OPEN_VOUCHERS " & _
"WHERE (((TBL_OPEN_VOUCHERS.[VOUCHER NUMBER])='" & wks.Cells(j, 1) & "') AND ((TBL_OPEN_VOUCHERS.[INVOICE NUMBER])='" & wks.Cells(j, 2) & "'));"
'"WHERE (((TBL_OPEN_VOUCHERS.[VOUCHER NUMBER])='" & wks.Cells(j, 1) & "'));"
Set rsCheckDuplicate = db.OpenRecordset(strSQLCheckDuplicate)
If rsCheckDuplicate.EOF Then
MsgBox "Voucher number " & wks.Cells(j, 1) & " not available in local system!"
Else
rsCheckDuplicate.MoveLast
rsCheckDuplicate.MoveFirst
If rsCheckDuplicate.RecordCount > 1 Then
MsgBox "Voucher number " & wks.Cells(j, 1) & " has multiple entries in local system! Please update manually!"
End If
If Len(wks.Cells(j, 3)) = 6 Then
strUpdateCC = "UPDATE TBL_OPEN_VOUCHERS SET TBL_OPEN_VOUCHERS.[CHARGE TO] = '" & wks.Cells(j, 3) & "', TBL_OPEN_VOUCHERS.COMMENTS_NOTES = '" & Form_FRM_MAIN.USER.Caption & ": PART OF MASS UPLOAD ON " & Now() & "' " & _
"WHERE (((TBL_OPEN_VOUCHERS.[VOUCHER NUMBER])='" & wks.Cells(j, 1) & "') AND ((TBL_OPEN_VOUCHERS.[INVOICE NUMBER])='" & wks.Cells(j, 2) & "'));"
'"WHERE (((TBL_OPEN_VOUCHERS.[VOUCHER NUMBER])='" & wks.Cells(j, 1) & "'));"
DoCmd.RunSQL strUpdateCC
succesfullyUpdated = succesfullyUpdated + 1
Else
MsgBox "Please check Cost Center"
End If
End If
Next
End If
Set wks = Nothing
MsgBox "Successfully uploaded " & succesfullyUpdated & " of " & i - 1 & " records!"
End If
End Sub
Private Sub Command7_Click()
On Error GoTo Err_Command7_Click
DoCmd.Close
Exit_Command7_Click:
Exit Sub
Err_Command7_Click:
MsgBox Err.Description
Resume Exit_Command7_Click
End Sub
Private Sub Ctl2003_Click()
If Me.Ctl2003 = False Then Me.Ctl2010 = True
If Me.Ctl2003 = True Then Me.Ctl2010 = False
End Sub
Private Sub Ctl2010_Click()
If Me.Ctl2010 = True Then Me.Ctl2003 = False
If Me.Ctl2010 = False Then Me.Ctl2003 = True
End Sub

What was the actual error message you were getting?
Have you tried creating a connection to the spreadsheet as a linked table, then treating the spreadsheet as a table?
Your code doesn't specify the datatype of the "wks" object, so the code doesn't know it is a spreadsheet.
Here's the approach I'd use:
Link the spreadsheet as a linked table (External Data, Import Excel Spreadsheet, Link to the DataSource.) This will create a "table" in access which is linked to a spreadsheet that is in a nominated location.
Use a query to identify records that are in your linked table but not in your local table (select s.* from upLoadSpreadsheet2010 s left outer join tbl_open_vouchers v on s.somekeycolumnidontknowthenameof = v.[voucher number] and s.someotherkeycolumn = v.[Invoice Number] where v.[voucher number] is null)
Open the query in your code, iterate through it, and do you thing, or better still create an Append query to do the job for you without any code at all.
The only challenge then is ensure the excel spreadsheet is in the right place at the right time. New spreadsheet? Just put it in the same place as the last spreadsheet and run the process again.

Related

I get a Run-time error 3075 - Syntax error (missing operator) in query expression '[OReqID] = And [Item] = '

I am making a database using MS Access for my NGO, where we receive requisitions for relief materials from different centers and accordingly, we place an order to the supplier or dispatch from our stock. So generally, one requisition will have any one outcome either an order or dispatch. But rarely we may also send some quantity as dispatch and the rest as order. For example, we received a requisition from CoochBehar for 500 blankets. We placed an order for 375 blankets and dispatched 125 blankets from our stock.
I have two buttons on the Requisition form 'Order' & 'Challan'. I want to enable or disable them according to the situation. For new records, both should be enabled. I made a subroutine at the beginning and call it on the load event and current event of the form. It works for the existing data but when I try to enter a new record the error pos up.
I am using the following code -
Sub Check_Order_Dispatch()
Dim OrdCount As Integer
Dim DispCount As Integer
Dim OrdQnty As Double
Dim DispQnty As Double
Dim Qnty As Double
OrdCount = DCount("[OrdID]", "T02_Order_Details", "[OReqID] = " & Me.Txt_ReqID & " And [Item] = " & Me.Req_Details_SubF.Form!Cmbo_Item)
DispCount = DCount("[DispID]", "T04_Dispatch_Details", "[DReqID] = " & Me.Txt_ReqID & " And [Item] = " & [Req_Details_SubF].[Form]![Cmbo_Item])
OrdQnty = Nz(DLookup("Quantity", "T02_Order_Details", "[OReqID] = " & [Txt_ReqID] & " And [Item] =" & [Req_Details_SubF].[Form]![Cmbo_Item]), 0)
DispQnty = Nz(DLookup("Quantity", "T04_Dispatch_Details", "[DReqID] = " & [Txt_ReqID] & " And [Item] =" & [Req_Details_SubF].[Form]![Cmbo_Item]), 0)
Qnty = Me.Req_Details_SubF.Form!Txt_Quantity
If IsNull(Me.Txt_ReqID) Then
Btn_Challan.Enabled = True
Btn_Order.Enabled = True
Else
If OrdCount > 0 And OrdQnty < Qnty Then
Btn_Challan.Enabled = True
Btn_Order.Enabled = True
ElseIf OrdCount > 0 And OrdQnty >= Qnty Then
Btn_Challan.Enabled = False
Btn_Order.Enabled = True
ElseIf DispCount > 0 And DispQnty < Qnty Then
Btn_Challan.Enabled = True
Btn_Order.Enabled = True
ElseIf DispCount > 0 And DispQnty >= Qnty Then
Btn_Challan.Enabled = True
Btn_Order.Enabled = False
Else
Btn_Challan.Enabled = False
Btn_Order.Enabled = False
End If
End If
End Sub
I tried all possibilities that came to mind but to no effect. I am not very good at VBA. Please guide me. Thanks in advance!

How to migrate In-app products from Google Play to Huawei AppGallery

I have an published in GooglePlay that I am migrating to Huawei AppGallery. Since my app have about 100 In-app products I would like to migrate them in some (semi)-automatic way.
I have done some research and I noticed that both platform offer import/export option.
However they do differ quite a lot - firstly in file format (CSV for Google, Excel for Huawei), secondly in data structure and type of parameters being exported, e.g.
Google CSV
Huawei AppGallery
ALl my products are consumables (no subscritpions).
Is there a fast way to do the migration?
I also had similar need recently and I ended up writing ruby script to achieve this.
require 'fileutils'
require "csv"
require 'rubygems'
require 'write_xlsx'
require 'optparse'
$DEBUG_INFO = false
XLSX_PRODUCT_ID_COLUMN_INDEX = 0
XLSX_PRODUCT_TYPE_COLUMN_INDEX = 1
XLSX_LANGUAGE_COLUMN_INDEX = 2
XLSX_CURRENCY_COLUMN_INDEX = 3
XLSX_PRICE_COLUMN_INDEX = 4
XLSX_SUBPERIOD_COLUMN_INDEX = 5
XLSX_HEADER_ROW = ['productId', 'productType', 'languages', 'currency', 'price', 'subPeriod']
XLSX_PRODUCT_ID_DESCRIPTION = 'The product ID must begin with a letter or number, and contains only letters (A-Z, a-z), numbers (0-9), underlines (_) or full stops (.)'
XLSX_PRODUCT_TYPE_DESCRIPTION = '0:Consumables 3:Non-consumables 2:Auto-renewable subscriptions(Product type cannot be edited once saved.)'
XLSX_LANGUAGES_DESCRIPTION = 'The product name must be a string of 1-55 characters, and the product description must be between 1-100 characters.The product name and the product description can not use use the following special characters ><\'"&$)%+\/#*,^|:. Enter a language in the format of \"Language type > Product name > Product description\". Separate different languages with a comma '
XLSX_CURRENCY_DESCRIPTION = 'The country and currency type used for pricing a product, are in the format: "Country - currency type".'
XLSX_PRICE_DESCRIPTION = 'Product price. Retain two decimal places, for example, 1.99. The system converts the entered price into the target price using the entered currency type and exchange rate, and will round the last digit of the price to 0, 6, or 9. Click this cell to view the Huawei special country currency requirements.'
XLSX_SUBPERIOD_DESCRIPTION = 'It is available only for a subscription. Supported values are [1 week, 1 month, 2 months, 3 months, 6 months, 1 year]'
XLSX_DESCRIPTION_ROW = [XLSX_PRODUCT_ID_DESCRIPTION, XLSX_PRODUCT_TYPE_DESCRIPTION, XLSX_LANGUAGES_DESCRIPTION, XLSX_CURRENCY_DESCRIPTION, XLSX_PRICE_DESCRIPTION, XLSX_SUBPERIOD_DESCRIPTION]
MICROUNIT_TO_UNIT_RATE = 1_000_000
CONSUMABLE_PRODUCT_TYPE = 0
AUTO_RENEWABLE_SUBSCRIPTION = 2
NON_CONSUMABLE_PRODUCT_TYPE = 3
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: example migrate_IAP_to_HAG.rb –s GoogleExampleCSV.csv –d HAGExcel.xlsx –c GB-GBP"
opts.on("-s", "--source_path ", "path to CSV file with Google IAP ") do |v|
options[:src_path] = v
puts "options[:src_path] = #{options[:src_path]}" if $DEBUG_INFO
end
opts.on("-d", "--destination_path ", "path where Excel with Huawei AppGallery products will be created ") do |v|
options[:dest_path] = v
puts "options[:dest_path] = #{options[:dest_path]}" if $DEBUG_INFO
end
opts.on("-c", "--currency ", "currency used as default for Google Play app, e.g. GB-GBP") do |v|
options[:currency] = v
puts "options[:currency] = #{options[:currency]}" if $DEBUG_INFO
end
end.parse!
#verify input
if not File.file?(options[:src_path])
raise "Input CSV file #{options[:src_path]} does not exists - please check if you provided right path"
end
destination_directory = File.dirname( options[:dest_path])
if not File.directory?(destination_directory)
puts "Directory ##{destination_directory} doesn't exist. Creating directory"
unless File.directory?(dirname)
FileUtils.mkdir_p(dirname)
end
end
puts 'Transforming Google Play CSV file into Huawei AppGallery Excel with IAP products'
#open destination file for editing
workbook = WriteXLSX.new( options[:dest_path])
worksheet = workbook.add_worksheet 'Preparing imported products'
def change_translation_format(google_translation)
langauge =''
title = ''
description = ''
result = ''
#remove not allowed characters ><'"&$)%+\/#*,^|:.
google_translation.gsub!(/[!><'"&$)%+\/#*,^|:.]/,'')
google_translation.split(';').each_with_index {|val, index|
case index%3
when 0 #item locale (language)
language = val.gsub(/[_]/, '-').strip #change en_US to en-US, strip removes whitespace from begining and end
result << language << '>'
when 1 # item description
title = val.strip
result << title << '>'
when 2 # item description
description = val.strip
result << description << ','
end
}
print "result = #{result}" if $DEBUG_INFO
return result
end
#Copy first 2 rows from Product Import Template
#write Excel headers in 1st row (starting from cell (0,0)
worksheet.write_row(0, 0, XLSX_HEADER_ROW)
#write Excel with header descriptions in 2nd row (starting from cell (1,0)
format = workbook.add_format()
format.set_text_wrap()
format.set_shrink()
worksheet.write_row(1, 0, XLSX_DESCRIPTION_ROW, format)
#start with 3rd (index starts from 0 so actually 2) row since first is header and second is with general information
excel_row_iterator = 2
number_of_products = 0
#Read Google CVS file and write data into Excel
CSV.foreach(options[:src_path], headers: true) do |row|
puts "excel_row_iterator = #{excel_row_iterator}, row = #{row}" if $DEBUG_INFO
product_id = row['Product ID']
print "product_id = #{product_id}" if $DEBUG_INFO
worksheet.write(excel_row_iterator, XLSX_PRODUCT_ID_COLUMN_INDEX, product_id)
worksheet.write(excel_row_iterator, XLSX_PRODUCT_TYPE_COLUMN_INDEX, CONSUMABLE_PRODUCT_TYPE)
google_translation_format = row['Locale; Title; Description']
print "Locale = #{google_translation_format}" if $DEBUG_INFO
translation = change_translation_format(google_translation_format)
worksheet.write(excel_row_iterator, XLSX_LANGUAGE_COLUMN_INDEX, translation)
worksheet.write(excel_row_iterator, XLSX_CURRENCY_COLUMN_INDEX, options[:currency])
price_microunits = row['Price'].to_f
print "price_microunits = #{price_microunits}" if $DEBUG_INFO
price = price_microunits / MICROUNIT_TO_UNIT_RATE
worksheet.write(excel_row_iterator, XLSX_PRICE_COLUMN_INDEX, price)
number_of_products += 1
excel_row_iterator += 1
end
puts ""
puts ""
puts "Transformation done, total IAP products number = #{number_of_products}"
workbook.close
puts "File saved as #{options[:dest_path]}"
`
You will require following gem packages to run script successfully
-csv
-fileutils
-write_xlsx
Now go to your main directly where you have your script file and exported google csv then run following command in command prompt:
ruby [your_script_name].rb -s GoogleExportedCSV.csv -d HAGExcel.xlsx -c GB-GBP
This should do the trick!

Trying to set up mailing button VB

I have an Email button but I cant get it to work it is doing notng and i don really know why.
`Private Sub Button2_Click_1(sender As Object, e As EventArgs) Handles tbsEmailRenewal.Click
On Error GoTo Err_cmdEMailInvoice_Click
If tbsEmailRenewal.Tag = "" Then Exit Sub
' Create Report
Dim ListReport = New FastReport.Report
ListReport.Load(My.Settings.SystemPath & "\Reports\EmailRenewalLetter.frx")
ListReport.SetParameterValue("CRMConnectionString", "Data Source=" & My.Settings.SQLServer & ";AttachDbFilename=;Initial Catalog=ICOM.Database;Integrated Security=False;Persist Security Info=False;User ID=CRMUser;Password=S0rtmypc!")
ListReport.SetParameterValue("MemberID", objMember.MemberID)
ListReport.Prepare()
' Create Export File
Dim PDFExport As FastReport.Export.Pdf.PDFExport = New FastReport.Export.Pdf.PDFExport
ListReport.Export(PDFExport, My.Settings.SystemPath & "Reports\EMailReport" & Format(objMember.MemberID, "00000") & ".pdf")
' Create EMail
Dim objOutlook As Object
Dim objMailMessage As Outlook.MailItem
objOutlook = CreateObject("Outlook.Application")
objMailMessage = objOutlook.CreateItem(0)
With objMailMessage
.To = txtEmailAddess1.Text
.Subject = "Renewal For " & lblMemberIDValue.Text
.Attachments.Add(My.Settings.SystemPath & "Reports\EMailReport" & Format(objMember.MemberID, "00000") & ".pdf")
.Display()
.Save()
.Close(Outlook.OlInspectorClose.olDiscard)
End With
objMailMessage = Nothing
objOutlook = Nothing
' Log It
Dim sMessage As String
sMessage = Replace(">" & Format(objMember.MemberID, "00000") & " to " & tbsEmailRenewal.Tag, "'", "`")
WriteAuditLogRecord(Me.Name, "tbsEmailRenewal.Click", "INFO", sMessage)
MsgBox("Email has been saved as a Draft", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "ICOM - Action Confirmed")
Err_cmdEMailInvoice_Click:
If Err.Number <> 0 Then
sErrDescription = Err.Description
WriteAuditLogRecord(Me.Name, "cmdEMailInvoice_Click", "Error", sErrDescription)
MsgBox("System Error occurred" & Chr(13) & "tbsEmailRenewal.Click" & Chr(13) & sErrDescription, MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "AztecCRM - Error Reporting")
End If
End Sub`
Are you sure that tbsEmailRenewal.Tag is not empty?
If tbsEmailRenewal.Tag = "" Then Exit Sub

Parsing EMail with VB6 - not splitting properly

When I parse through an email that looks like:
included_po~301993959 'VBCRLF
po_no~vendor~part_no~class~type_code~buyer~qty_ordered~measure~balance_on_order~cost~amt_ordered~order_date~delivery_date~ship_Date~receive_date~open~wo_no 'VBCRLF
301993959~100000~88008K~PROBE 800~F~VAX~4.0 ~EA~4.0~100.3300~401.32000~011513~012313~012313~000000~Y~STOCK 'VBCRLF
301993959~100000~TFCI-010-50~WIRE SPTEF~F~VAX~1.0~SP~1.0~12.6400~12.64000~011513~012313~012313~000000~Y~STOCK 'VBCRLF
301993959~100000~TFIR-010-50~WIRE SPTEF~F~VAX~1.0~SP~1.0~12.6400~12.64000~011513~012313~012313~000000~Y~STOCK 'VBCRLF
using code:
Public Sub AddItems()
Dim aLineItem() As String
Dim aItem() As String
Dim i As Integer
Dim j As Integer
Dim iCnt As Double
Dim msg
Dim Item As Items
ReDim sWo(0)
iCnt = 0
For i = 1 To UBound(sMsg())
aLineItem = Split(sMsg(i), vbCrLf)
For j = 1 To UBound(aLineItem)
If aLineItem(j) <> "" Then
If blah = 1 Then
Debug.Print ("...." & aLineItem(j))
End If
aItem = Split(aLineItem(j), "~")
If (aItem(0) <> "") And (aItem(0) <> "included_po") And (aItem(0) <> "po_no") Then
Item.PO_num = GetWo(aItem(1))
If Item.PO_num <> "0" Then
Item.Company = aItem(1)
Item.Delivery_date = aItem(12)
Item.pn = aItem(2)
Item.QTY_ordered = aItem(6)
Item.Unit_Price = aItem(9)
End If 'If Item.PO_num <> "0" Then
End If 'If aItem(1) <> "" Then
End If ' If aLineItem(j) <> "" Then
Next j
Next i
End Sub
The email parsing looks like this:
....301993959~100000~88008K~PROBE
....8800~F~VAX~4.0~EA~4.0~100.3300~401.32000~011513~012313~012313~000000~Y~S
....TOCK
Is there a better way to parse this email?
EDIT #1:
Public Sub GetMailMsg()
Dim pop3 As jmail.pop3
Dim iCount As Integer
Dim i As Integer
Dim mailID As Integer
Dim j As Integer
Dim sSubject As String
j = 0
ReDim sMsg(0)
'connect to the mail box
Set pop3 = New pop3
pop3.Connect "REMOVED FOR SECURITY"
'Get message count
iCount = pop3.Count
'Read Messages
For i = 1 To iCount
sSubject = pop3.Messages.Item(i).Subject
Label1.Caption = "Reading message.." & sSubject
DoEvents
If InStr(sSubject, "China Purchase Orders") <> 0 Then 'email test
j = j + 1
ReDim Preserve sMsg(j)
sMsg(j) = pop3.Messages.Item(i).Body
Label1.Caption = "Reading mail message for order " & sSubject
If blah = 1 Then
Debug.Print ("Reading mail message for order " & sSubject)
Debug.Print ("Reading mail message for order " & sMsg(j))
End If
End If
Next
pop3.Disconnect
Set pop3 = Nothing
End SUb
--EDIT #2
OUTPUT FROM DEBUG:
Reading mail message for order China Purchase Orders
Reading mail message for order
included_po~301993959
po_no~vendor~part_no~class~type_code~buyer~qty_ordered~measure~balance_o 'VBCRLF
n_order~cost~amt_ordered~order_date~delivery_date~ship_Date~receive_date 'VBCRLF
~open~wo_no 'VBCRLF
301993959~100000~88008K~PROBE 'VBCRLF
8800~F~VAX~4.0~EA~4.0~100.3300~401.32000~011513~012313~012313~000000~Y~S 'VBCRLF
TOCK 'VBCRLF
301993959~100000~TFCI-010-50~WIRE 'VBCRLF
SPTEF~F~VAX~1.0~SP~1.0~12.6400~12.64000~011513~012313~012313~000000~Y~ST 'VBCRLF
OCK 'VBCRLF
301993959~100000~TFIR-010-50~WIRE 'VBCRLF
SPTEF~F~VAX~1.0~SP~1.0~12.6400~12.64000~011513~012313~012313~000000~Y~ST 'VBCRLF
OCK 'VBCRLF
Your lines aren't breaking up properly makes me think there is a problem in the line aLineItem = Split(sMsg(i), vbCrLf). Please check whether you don't have any vbCrLF in the line you aren't getting right.
Is that line one continuous line?
Edit #1 # Jan 16, 2013 1:16pm EST:
I created a file and pasted provided input.
I created a simple program and incorporated your code into it. Please see produced DEBUG below, consisting as expected with 3 lines beginning with 301993959 and ending with STOCK. This is the correct and desirable output, right?
....301993959~100000~TFCI-010-50~WIRE SPTEF~F~VAX~1.0~SP~1.0~12.6400~12.64000~011513~012313~012313~000000~Y~STOCK
....301993959~100000~TFIR-010-50~WIRE SPTEF~F~VAX~1.0~SP~1.0~12.6400~12.64000~011513~012313~012313~000000~Y~STOCK
....301993959~100000~88008K~PROBE 800~F~VAX~4.0 ~EA~4.0~100.3300~401.32000~011513~012313~012313~000000~Y~STOCK
So the code you provided is working fine. If you say the input file is fine too, that means the issue is with how you are reading that email, specifically how you populate sMsg(). Can you post that code please?
Edit #2 # Jan 16, 2013 2:32pm EST:
You are getting some unwanted vbCrLfs in your single record line and you can't split it the way you want. Here is what I suggest you do:
1) If you can modify GetMailMsg to instead of loading Body as it is, go through line by line to avoid generating unwanted vbCrLfs. I have zero experience with pop objects so I don't know if that is possible.
2) If the number of unwanted cbCrLfs is consistent, ex: 2 in a single record, then you can simply adjust your code to concatenate split records like this
DIM concatLine As String
For j = 1 To UBound(aLineItem) Step 3
concatLine = aLineItem(j) & aLineItem(j+1) & aLineItem(j+2)
If concatLine <> "" Then
If blah = 1 Then
Debug.Print ("...." & concatLine)
End If
aItem = Split(concatLine, "~")
If (aItem(0) <> "") And (aItem(0) <> "included_po") And (aItem(0) <> "po_no") Then
Item.PO_num = GetWo(aItem(1))
If Item.PO_num <> "0" Then
Item.Company = aItem(1)
Item.Delivery_date = aItem(12)
Item.pn = aItem(2)
Item.QTY_ordered = aItem(6)
Item.Unit_Price = aItem(9)
End If 'If Item.PO_num <> "0" Then
End If 'If aItem(1) <> "" Then
End If ' If concatLine <> "" Then
Next j
3) or better yet, concat string until you reach the end of the record and then split that concatenated string.
DIM concatLine As String
DIM detailsRecord as Integer
For detailsRecord = 1 To UBound(aLineItem)
if LCase(Right(aLineItem(detailsRecord),5)) = 'wo_no' Then Exit For ' when we find this tag, we know where details record begin
Next detailsRecord
For j = detailsRecord + 1 To UBound(aLineItem) ' begin looping detail records
concatLine = concatLine + aLineItem(j)
If UCase(Right(aLineItem(j), 5)) = "STOCK" Then ' this is your end of the record indicator
If blah = 1 Then
Debug.Print ("...." & concatLine)
End If
aItem = Split(concatLine, "~")
If (aItem(0) <> "") Then
Item.PO_num = GetWo(aItem(1))
If Item.PO_num <> "0" Then
Item.Company = aItem(1)
Item.Delivery_date = aItem(12)
Item.pn = aItem(2)
Item.QTY_ordered = aItem(6)
Item.Unit_Price = aItem(9)
End If 'If Item.PO_num <> "0" Then
End If 'If aItem(1) <> "" Then
End If ' If concatLine <> "" Then
concatLine = ""
Next j
For cases 2 and 3, don't forget to handle the headers first- you will have to move If (aItem(0) <> "") And (aItem(0) <> "included_po") And (aItem(0) <> "po_no") outside the main loop to handle header records (i believe the first 2 or records are headers).
EDIT #3:
I fixed scenario #3 to skip through the header records (assuming 'wo_no' is an indicator of the end of that record), then to concatenate strings to form a single record by searching for an end tag ("STOCK"). This method is going to be flexible enough to handle dynamic number of vbCrLfs in the email body that splits a single record into unpredictable number of strings.
The code was typed in the browser, so I don't guarantee it will work :)
Since you know what should start each line, then use the Split function using "301993959".
Dim LineItems(100) As String
x = Split(sMsg(i), "301993959")
For j = 1 To UBound(x) - 1 'Don't use 0 becuase you don't need that part
LineItems(j - 1) = x(j)
Next i
Of Course you could take it one step further by then splitting each item in the string using "~" as your second delimiter.
Dim LineItems(100, 15) As String
x = Split(Text1.Text, "301993959")
For j = 1 To UBound(x) - 1 'Don't use 0 becuase you don't need that part
y = Split(x(j), "~")
For k = 1 To 15
LineItems(j - 1, k) = y(k)
Next k
Next j

ABCPDF not rendering links

I am using the AddImageUrl function of the ABCPDF library and getting the pages to render fine as PDFs. But I am having a problem where the links (a tags) are not getting rendered in the PDF links but rather as normal text without the link functionality. I have checked the HTML page to make sure that the links exist on the page.
I figured this out. Hopefully, this will help someone else who has this problem. You need to include the following lines before generating the pdf to make the links active.
theDoc.HtmlOptions.AddLinks = true;
We are using ABCPDF.Net version 6 to create a PDF file from HTML. However, the links are not live except for those that appear as URLs in the HTML even when HtmlOptions.AddLinks is set to true. In fact, when it's set to true, the links render with a brown background not present when it's set to false. Here is the code we use to create the PDF using vb.net
Dim theID As Object
Dim pageRect As String
Dim Header As String = Nothing
If SubBank.Length <> 0 Then
If HttpContext.Current.Session("BankType") IsNot Nothing And (HttpContext.Current.Session("BankType") = 1 Or HttpContext.Current.Session("BankType") = 4) Then
Header = "<br/><br/> <br/><br/><div class='bankname1' align='center'>" & SubBank & " </div><div style='float:right'><img src='" & getBaseUrl() & "/Images_Modern/SGPSMainLogo.png' /> </div>"
Else
Header = "<br/><br/> <br/><br/><div class='bankname1' align='center'>" & SubBank & " </div><div style='float:right'><img src='" & getBaseUrl() & "/Images_Modern/bankers_gps_logo_pdf.gif' /> </div>"
End If
If PeerGroup.Length <> 0 AndAlso HttpContext.Current.Session("Product_Id") = 1 Then
Header &= "<div class='bankname2' align='center'>Vs " & PeerGroup & " </div>"
End If
strContent = Header & strContent
End If
Dim objAbc As New WebSupergoo.ABCpdf6.Doc
objAbc.Rect.Inset(15, 15)
CreateErrorText(Header)
Dim ObjSet As New PDFSettings
ObjSet.objAbc = objAbc
ObjSet.OriWidth = objAbc.MediaBox.Width
ObjSet.OriHeight = objAbc.MediaBox.Height
objAbc.HtmlOptions.AddLinks = True
objAbc.HtmlOptions.TargetLinks = True
'objAbc.HtmlOptions.MaxAtomicImageSize = 100
'objAbc.HtmlOptions.ImageQuality = 101
ObjSet.Rotate(Orientation)
'theID = objAbc.AddImageHtml(strContent, True, 0, False)
'objAbc.SetInfo(theID, "/Rotate", "90")
theID = objAbc.AddImageHtml(strContent)
objAbc.Rendering.DotsPerInch = 96S
pageRect = objAbc.Rect.String
Do
'theDoc.FrameRect
If Not objAbc.Chainable(theID) Then Exit Do
objAbc.Page = objAbc.AddPage()
theID = objAbc.AddImageToChain(theID)
Loop
Dim i
For i = 1 To objAbc.PageCount
objAbc.PageNumber = i
objAbc.Flatten()
Next
'added By yuvraj For NS Headder :17/04/2012
If (strContent.IndexOf("NSHEADSTART") > -1) Then
objAbc.HPos = 0.5
objAbc.VPos = 0.5
' objAbc.Color.String = "0 255 0"
objAbc.FontSize = 16
For i = 1 To objAbc.PageCount
objAbc.PageNumber = i
objAbc.Rect.Pin = 0
objAbc.Rect.String = "20 20 400 400"
objAbc.HPos = 0.5
objAbc.AddHtml(getHeadText(strContent))
objAbc.Rect.Move(200, 500)
objAbc.Rect.String = pageRect
objAbc.HPos = 0
Next
End If
'theDoc.Rect.Move 0, -50
objAbc.HPos = 0
objAbc.Save(PDFPath)
objAbc.Clear()
'Response.Redirect(".\PDF\manoj12.pdf")
objAbc = Nothing
theID = Nothinge

Resources