ABCPDF not rendering links - hyperlink

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

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!

what`s wrong with 'iup.config' in iup package on lua

I started to learn lua (version 5.1) plus iup (version 3.5) library, but this issue shut me down :(
So, the clearest example from iup tutorial http://webserver2.tecgraf.puc-rio.br/iup/en/tutorial/tutorial3.html#Recent_Config
require("iuplua")
require("iupluaimglib")
--********************************** Utilities *****************************************
function str_find(str, str_to_find, casesensitive, start)
if (not casesensitive) then
return str_find(string.lower(str), string.lower(str_to_find), true, start)
end
return string.find(str, str_to_find, start, true)
end
function read_file(filename)
local ifile = io.open(filename, "r")
if (not ifile) then
iup.Message("Error", "Can't open file: " .. filename)
return nil
end
local str = ifile:read("*a")
if (not str) then
iup.Message("Error", "Fail when reading from file: " .. filename)
return nil
end
ifile:close()
return str
end
function write_file(filename, str)
local ifile = io.open(filename, "w")
if (not ifile) then
iup.Message("Error", "Can't open file: " .. filename)
return false
end
if (not ifile:write(str)) then
iup.Message("Error", "Fail when writing to file: " .. filename)
end
ifile:close()
return true
end
--********************************** Main (Part 1/2) *****************************************
-- it`s there:
config = iup.config{} ------ here it is, first error
config.app_name = "simple_notepad"
config:Load()
lbl_statusbar = iup.label{title = "Lin 1, Col 1", expand = "HORIZONTAL", padding = "10x5"}
multitext = iup.text{
multiline = "YES",
expand = "YES"
}
font = config:GetVariable("MainWindow", "Font")
if (font) then
multitext.font = font
end
item_open = iup.item{title = "&Open...\tCtrl+O"}
item_saveas = iup.item{title="Save &As...\tCtrl+S"}
item_font = iup.item{title="&Font..."}
item_about = iup.item{title="&About..."}
item_find = iup.item{title="&Find...\tCtrl+F"}
item_goto = iup.item{title="&Go To..."}
item_exit = iup.item{title="E&xit"}
--********************************** Callbacks *****************************************
function config:recent_cb()
local filename = self.title
local str = read_file(filename)
if (str) then
multitext.value = str
end
end
function multitext:caret_cb(lin, col)
lbl_statusbar.title = "Lin "..lin..", Col "..col
end
function item_open:action()
local filedlg = iup.filedlg{
dialogtype = "OPEN",
filter = "*.txt",
filterinfo = "Text Files",
parentdialog=iup.GetDialog(self)
}
filedlg:popup(iup.CENTERPARENT, iup.CENTERPARENT)
if (tonumber(filedlg.status) ~= -1) then
local filename = filedlg.value
local str = read_file(filename)
if (str) then
config:RecentUpdate(filename)
multitext.value = str
end
end
filedlg:destroy()
end
function item_saveas:action()
local filedlg = iup.filedlg{
dialogtype = "SAVE",
filter = "*.txt",
filterinfo = "Text Files",
parentdialog=iup.GetDialog(self)
}
filedlg:popup(iup.CENTERPARENT, iup.CENTERPARENT)
if (tonumber(filedlg.status) ~= -1) then
local filename = filedlg.value
if (write_file(filename, multitext.value)) then
config:RecentUpdate(filename)
end
end
filedlg:destroy()
end
function item_exit:action()
config:DialogClosed(iup.GetDialog(self), "MainWindow")
config:Save()
config:destroy()
return iup.CLOSE
end
function item_goto:action()
local line_count = multitext.linecount
local lbl_goto = iup.label{title = "Line Number [1-"..line_count.."]:"}
local txt_goto = iup.text{mask = iup.MASK_UINT, visiblecolumns = 20} --unsigned integer numbers only
local bt_goto_ok = iup.button{title = "OK", text_linecount = 0, padding = "10x2"}
bt_goto_ok.text_linecount = line_count
function bt_goto_ok:action()
local line_count = tonumber(self.text_linecount)
local line = tonumber(txt_goto.value)
if (line < 1 or line >= line_count) then
iup.Message("Error", "Invalid line number.")
return
end
goto_dlg.status = 1
return iup.CLOSE
end
local bt_goto_cancel = iup.button{title = "Cancel", padding = "10x2"}
function bt_goto_cancel:action()
goto_dlg.status = 0
return iup.CLOSE
end
local box = iup.vbox{
lbl_goto,
txt_goto,
iup.hbox{
iup.fill{},
bt_goto_ok,
bt_goto_cancel,
normalizesize="HORIZONTAL",
},
margin = "10x10",
gap = "5",
}
goto_dlg = iup.dialog{
box,
title = "Go To Line",
dialogframe = "Yes",
defaultenter = bt_goto_ok,
defaultesc = bt_goto_cancel,
parentdialog = iup.GetDialog(self)
}
goto_dlg:popup(iup.CENTERPARENT, iup.CENTERPARENT)
if (tonumber(goto_dlg.status) == 1) then
local line = txt_goto.value
local pos = iup.TextConvertLinColToPos(multitext, line, 0)
multitext.caretpos = pos
multitext.scrolltopos = pos
end
goto_dlg:destroy()
end
function item_find:action()
local find_dlg = self.find_dialog
if (not find_dlg) then
local find_txt = iup.text{visiblecolumns = "20"}
local find_case = iup.toggle{title = "Case Sensitive"}
local bt_find_next = iup.button{title = "Find Next", padding = "10x2"}
local bt_find_close = iup.button{title = "Close", padding = "10x2"}
function bt_find_next:action()
local find_pos = tonumber(find_dlg.find_pos)
local str_to_find = find_txt.value
local casesensitive = (find_case.value == "ON")
-- test again, because it can be called from the hot key
if (not str_to_find or str_to_find:len()==0) then
return
end
if (not find_pos) then
find_pos = 1
end
local str = multitext.value
local pos, end_pos = str_find(str, str_to_find, casesensitive, find_pos)
if (not pos) then
pos, end_pos = str_find(str, str_to_find, casesensitive, 1) -- try again from the start
end
if (pos) and (pos > 0) then
pos = pos - 1
find_dlg.find_pos = end_pos
iup.SetFocus(multitext)
multitext.selectionpos = pos..":"..end_pos
local lin, col = iup.TextConvertPosToLinCol(multitext, pos)
local pos = iup.TextConvertLinColToPos(multitext, lin, 0) -- position at col=0, just scroll lines
multitext.scrolltopos = pos
else
find_dlg.find_pos = nil
iup.Message("Warning", "Text not found.")
end
end
function bt_find_close:action()
iup.Hide(iup.GetDialog(self)) -- do not destroy, just hide
end
box = iup.vbox{
iup.label{title = "Find What:"},
find_txt,
find_case,
iup.hbox{
iup.fill{},
bt_find_next,
bt_find_close,
normalizesize="HORIZONTAL",
},
margin = "10x10",
gap = "5",
}
find_dlg = iup.dialog{
box,
title = "Find",
dialogframe = "Yes",
defaultenter = bt_next,
defaultesc = bt_close,
parentdialog = iup.GetDialog(self)
}
-- Save the dialog to reuse it
self.find_dialog = find_dlg -- from the main dialog */
end
-- centerparent first time, next time reuse the last position
find_dlg:showxy(iup.CURRENT, iup.CURRENT)
end
function item_font:action()
local font = multitext.font
local fontdlg = iup.fontdlg{value = font, parentdialog=iup.GetDialog(self)}
fontdlg:popup(iup.CENTERPARENT, iup.CENTERPARENT)
if (tonumber(fontdlg.status) == 1) then
multitext.font = fontdlg.value
config:SetVariable("MainWindow", "Font", fontdlg.value)
end
fontdlg:destroy()
end
function item_about:action()
iup.Message("About", " Simple Notepad\n\nAutors:\n Gustavo Lyrio\n Antonio Scuri")
end
--********************************** Main (Part 2/2) *****************************************
recent_menu = iup.menu{}
file_menu = iup.menu{
item_open,
item_saveas,
iup.separator{},
iup.submenu{title="Recent &Files", recent_menu},
item_exit
}
edit_menu = iup.menu{item_find, item_goto}
format_menu = iup.menu{item_font}
help_menu = iup.menu{item_about}
sub_menu_file = iup.submenu{file_menu, title = "&File"}
sub_menu_edit = iup.submenu{edit_menu, title = "&Edit"}
sub_menu_format = iup.submenu{format_menu, title = "F&ormat"}
sub_menu_help = iup.submenu{help_menu, title = "&Help"}
menu = iup.menu{
sub_menu_file,
sub_menu_edit,
sub_menu_format,
sub_menu_help,
}
btn_open = iup.button{image = "IUP_FileOpen", flat = "Yes", action = item_open.action, canfocus="No", tip = "Open (Ctrl+O)"}
btn_save = iup.button{image = "IUP_FileSave", flat = "Yes", action = item_saveas.action, canfocus="No", tip = "Save (Ctrl+S)"}
btn_find = iup.button{image = "IUP_EditFind", flat = "Yes", action = item_find.action, canfocus="No", tip = "Find (Ctrl+F)"}
toolbar_hb = iup.hbox{
btn_open,
btn_save,
iup.label{separator="VERTICAL"},
btn_find,
margin = "5x5",
gap = 2,
}
vbox = iup.vbox{
toolbar_hb,
multitext,
lbl_statusbar,
}
dlg = iup.dialog{
vbox,
title = "Simple Notepad",
size = "HALFxHALF",
menu = menu,
close_cb = item_exit.action,
}
function dlg:k_any(c)
if (c == iup.K_cO) then
item_open:action()
elseif (c == iup.K_cS) then
item_saveas:action()
elseif (c == iup.K_cF) then
item_find:action()
elseif (c == iup.K_cG) then
item_goto:action()
end
end
config:RecentInit(recent_menu, 10)
-- parent for pre-defined dialogs in closed functions (IupMessage)
iup.SetGlobal("PARENTDIALOG", iup.SetHandleName(dlg))
config:DialogShow(dlg, "MainWindow")
-- to be able to run this script inside another context
if (iup.MainLoopLevel()==0) then
iup.MainLoop()
iup.Close()
end
don`t working:
error output:
wlua: source.wlua:52: attempt to call field 'config' (a nil value)
So, why it isn`t working?

IE11 clears password fields on page refresh:

Happens only in IE (Chrome and Firefox, no issues... go figure)
I have a page where customer's can update their details (name, address,password etc.) and everything is working fine, however if the customer submits the form (which also works fine) and then presses the back button all the customer's information will repopulate the form except for the password field.
My boss would like this to repopulate as well, like it does in Chrome and Firefox, but IE won't do it. I'm hoping it's something simple I've missed but I can't see it. I've tried adjusting the lines where the text fields are populated to match the rest of the form, but that just results in empty fields. Code below.
Page_Load
If TypeOf Session("Customer") Is GPCUser Then
c = CType(Session("Customer"), GPCUser)
Else
Response.Redirect("default.aspx")
End If
If Not Page.IsPostBack Then
If c.CustomerID > 0 Then
'populate the table
lblAccountName.Text = c.AccountName
txtFirstName.Text = c.FirstName
txtLastName.Text = c.LastName
txtEmail.Text = c.Email
txtAddress.Text = c.Address
txtSuburb.Text = c.Suburb
txtCityTown.Text = c.City
txtPostcode.Text = c.PostCode
txtPhone.Text = c.Phone
txtMobile.Text = c.Mobile
'chkNewsletter.checked = c.Newsletter
txtPassword.Attributes.Add("value", c.GeneratedPassword)
txtConfirmPassword.Attributes.Add("value", c.GeneratedPassword)
'txtPassword.Text = c.GeneratedPassword
'txtConfirmPassword.Text = c.GeneratedPassword
Dim subscriptions As ContactSubscriptions = New ContactSubscriptions(c.CustomerID)
chkGenernalNewsletters.Checked = subscriptions.IsGenernalNewsletters
End If
Else
End If
Update Button
If TypeOf Session("Customer") Is GPCUser Then
c = CType(Session("Customer"), GPCUser)
Else
Exit Sub
End If
c.AccountName = lblAccountName.Text
c.FirstName = txtFirstName.Text
c.LastName = txtLastName.Text
c.Email = txtEmail.Text
c.Address = txtAddress.Text
c.Suburb = txtSuburb.Text
c.City = txtCityTown.Text
c.PostCode = txtPostcode.Text
c.Phone = txtPhone.Text
c.Mobile = txtMobile.Text
'c.Newsletter = chkNewsletter.Checked
c.GeneratedPassword = txtPassword.Text
c.CustomerUpdatedRequired = false
'Update password field
txtPassword.Attributes.Add("value", c.GeneratedPassword)
txtConfirmPassword.Attributes.Add("value", c.GeneratedPassword)
GPCUser.AddUpdateCustomer(c)
subscriptions.IsGenernalNewsletters = chkGenernalNewsletters.Checked
subscriptions.Save()
Session("Customer") = c
lblMessage.Text = "Your details have been successfully updated."
pnlUpdateAccount.Visible = False

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

dao recordset updating the wrong record

I'm trying to have a form usable for both creating a new record or updating another. Currently it is doing it through the value of a textbox (new or edit). The structure works fine, but for some reason, when it is performing the edit function, it is saving changes to the wrong record. For instance, if I am editing record 1027, when i submit it, it'll update record 1073. Its consistent, it'll always update the same, wrong record. Edit 1000, it'll update 1073; if i update 1081, it'll update 1073, and so on. Is there a way to specify which record it should be editing? yes, the record number is the primary key/id. Heres the code:
Private Sub btnSubmit_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strTable As String
Dim strField As String
Dim ID As Long
Dim newID As Long
strTable = "record_holdData"
Set db = CurrentDb
Set rs = db.OpenRecordset(strTable)
'button has 2 modes
If txtMode.Value = "NEW" Then
With rs
.AddNew
.Fields("PO_no") = txtPONum
.Fields("prodSupervisor") = cboProdSup
.Fields("qaSupervisor") = cboQASup
.Fields("labTech") = cboLabTech
.Fields("flavor") = cboFlavor
.Fields("lineNumber") = cboLineNumber
.Fields("container") = cboContainer
.Fields("package") = cboPackage
.Fields("holdQty") = txtQty
.Fields("productionDate") = txtProdDate
.Fields("dateCode") = txtDatecode
.Fields("component") = cboComponent
.Fields("nonconformance") = cboDiscrepancy
.Fields("foundDuring") = cboFoundAt
.Fields("responsibility") = cboRespCode
.Fields("comments") = txtDescription
.Fields("rootCause") = txtRootCause
.Fields("holdStatus") = 1
.Fields("dateOpened") = Now()
.Update
.Bookmark = .LastModified
newID = !ID
End With
MsgBox ("Hold information saved!")
btnPrintTag.Enabled = True
DoCmd.OpenReport "Holdtag", acViewPreview, , "[ID] = " & newID
DoCmd.Close
ElseIf txtMode.Value = "EDIT" Then
'do editing stuff
With rs
.Edit
.Fields("PO_no") = txtPONum
.Fields("prodSupervisor") = cboProdSup
.Fields("qaSupervisor") = cboQASup
.Fields("labTech") = cboLabTech
.Fields("flavor") = cboFlavor
.Fields("lineNumber") = cboLineNumber
.Fields("container") = cboContainer
.Fields("package") = cboPackage
.Fields("holdQty") = txtQty
.Fields("productionDate") = txtProdDate
.Fields("dateCode") = txtDatecode
.Fields("component") = cboComponent
.Fields("nonconformance") = cboDiscrepancy
.Fields("foundDuring") = cboFoundAt
.Fields("responsibility") = cboRespCode
.Fields("comments") = txtDescription
.Fields("rootCause") = txtRootCause
.Fields("lastEditDate") = Now()
.Update
End With
MsgBox ("Information Updated")
End If
End Sub
Sorry i caught it. Problem was I was basically redefining the recordset each time the subroutine was called. I changed the second block to the following:
ElseIf txtMode.Value = "EDIT" Then
'do editing stuff
Set rs = db.OpenRecordset("SELECT * FROM record_holdData WHERE ID=" & txtID)
With rs
.Edit
.Fields("PO_no") = txtPONum
.Fields("prodSupervisor") = cboProdSup
.Fields("qaSupervisor") = cboQASup
.Fields("labTech") = cboLabTech
.Fields("flavor") = cboFlavor
.Fields("lineNumber") = cboLineNumber
.Fields("container") = cboContainer
.Fields("package") = cboPackage
.Fields("holdQty") = txtQty
.Fields("productionDate") = txtProdDate
.Fields("dateCode") = txtDatecode
.Fields("component") = cboComponent
.Fields("nonconformance") = cboDiscrepancy
.Fields("foundDuring") = cboFoundAt
.Fields("responsibility") = cboRespCode
.Fields("comments") = txtDescription
.Fields("rootCause") = txtRootCause
.Fields("lastEditDate") = Now()
.Update
End With

Resources