I am using HP (Microfocus) Quality Center 12.5 and designed a button using the toolbar in Workflow.
The following code pulls the first value from the RecordSet but not all values. How do I pull all values from the RecordSet and display it?
Sub searchDefects()
On Error Resume Next
Dim a
a = InputBox("Enter search query")
set TD1 = TDConnection
set com1 = TD1.command
com1.CommandText = "Select BG_BUG_ID FROM BUG WHERE BG_DESCRIPTION LIKE '%"
&a &"%'"
set rec1 = com1.Execute
Dim i
DIM msg
msg = ""
rec1.First
For i = 0 to rec1.RecordCount
msg = msg & "," & rec1.FieldValue(i) & ","
rec1.Next()
Next
MsgBox msg
On Error GoTo 0
End Sub
I found a solution after trial and error but still don't know the reason behind the root cause and how it is solving it. Any feedback is appreciated.
Sub SearchDefectsDescription()
On Error Resume Next
Dim a
a = InputBox("Enter search query for Description field")
set TD1 = TDConnection
set com1 = TD1.command
com1.CommandText = "Select BG_BUG_ID FROM BUG WHERE BG_DESCRIPTION LIKE '%" &a &"%'"
set rec1 = com1.Execute
Dim i
DIM msg
msg = "Bug ID" & vbnewline
rec1.First
If a = vbCancel Then
MsgBox "Search is cancelled"
Exit Sub
ElseIf Len(a) = 0 Then
MsgBox "Search input is empty, plesea try again."
Exit Sub
Else
For i = 0 to rec1.RecordCount
msg = msg & rec1.FieldValue(0) & rec1.FieldValue(1) & " "
rec1.Next()
Next
End If
MsgBox msg
On Error GoTo 0
End Sub
Related
I have a code to insert all data from different excel files located in one folder as a loop ,
but the inserted data comes as a table (Vertically) , here is my question
what is the required modification to the existing code to make the inserted data transpose horizontally??????? thanks in advance
here is the pic of loaded data, i need these table to be shown horizontally
enter image description here
here is my code
Sub Basic_Example_1()
Dim MyPath As String, FilesInPath As String
Dim MyFiles() As String
Dim SourceRcount As Long, Fnum As Long
Dim mybook As Workbook, BaseWks As Worksheet
Dim sourceRange As Range, destrange As Range
Dim rnum As Long, CalcMode As Long
'Fill in the path\folder where the files are
MyPath = "C:\Users\mjamal\Desktop\Downloads\Sensor1"
'Add a slash at the end if the user forget it
If Right(MyPath, 1) <> "\" Then
MyPath = MyPath & "\"
End If
'If there are no Excel files in the folder exit the sub
FilesInPath = Dir(MyPath & "*.xl*")
If FilesInPath = "" Then
MsgBox "No files found"
Exit Sub
End If
'Fill the array(myFiles)with the list of Excel files in the folder
Fnum = 1
Do While FilesInPath <> ""
Fnum = Fnum + 1
ReDim Preserve MyFiles(1 To Fnum)
MyFiles(Fnum) = FilesInPath
FilesInPath = Dir()
Loop
'Change ScreenUpdating, Calculation and EnableEvents
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
.EnableEvents = False
End With
Set BaseWks = Worksheets("Sheet1")
rnum = 5
'Loop through all files in the array(myFiles)
If Fnum > 0 Then
For Fnum = LBound(MyFiles) To UBound(MyFiles)
Set mybook = Nothing
On Error Resume Next
Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))
On Error GoTo 0
If Not mybook Is Nothing Then
On Error Resume Next
With mybook.Worksheets(1)
Set sourceRange = .Range("B1:BB7")
End With
If Err.Number > 0 Then
Err.Clear
Set sourceRange = Nothing
Else
'if SourceRange use all columns then skip this file
If sourceRange.Columns.Count >= BaseWks.Columns.Count Then
Set sourceRange = Nothing
End If
End If
On Error GoTo 0
If Not sourceRange Is Nothing Then
SourceRcount = sourceRange.Rows.Count
If rnum + SourceRcount >= BaseWks.Rows.Count Then
MsgBox "Sorry there are not enough rows in the sheet"
BaseWks.Columns.AutoFit
mybook.Close savechanges:=False
GoTo ExitTheSub
Else
'Copy the file name in column A
With sourceRange
BaseWks.Cells(rnum, "C"). _
Resize(.Rows.Count).Value = MyFiles(Fnum)
End With
'Set the destrange
Set destrange = BaseWks.Range("G" & rnum)
'we copy the values from the sourceRange to the destrange
With sourceRange
Set destrange = destrange. _
Resize(.Rows.Count, .Columns.Count)
End With
destrange.Value = sourceRange.Value
rnum = rnum + SourceRcount + 5
End If
End If
mybook.Close savechanges:=False
End If
Next Fnum
BaseWks.Columns.AutoFit
End If
ExitTheSub:
'Restore ScreenUpdating, Calculation and EnableEvents
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = CalcMode
End With
End Sub
I try to save outlook mails within an SQL-BLOB-Field as eml (or raw) content.
I have a form within MS Access to get the mails from outlook code:
Dim objitem As Outlook.MailItem
Set objOutlook = New Outlook.Application
Set objMapiFolder = objOutlook.Session.Folders("USER").Folders("Posteingang")
Dim inboundemail As ADODB.Recordset
Set inboundemail = New ADODB.Recordset
inboundemail.Open "Inbound_EMail_Buffer", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Set MailList = objMapiFolder.Items
Dim senderMail As String
Dim ReceiverMail As String
FillAddress
Dim SAfeMailItem
Set SAfeMailItem = CreateObject("Redemption.SafeMailItem")
For Each objitem In MailList
If objitem.Class = olMail Then
With objitem
inboundemail.AddNew
Select Case .SenderEmailType
Case "SMTP"
senderMail = .SenderEmailAddress
Case "EX"
senderMail = FindAddress(.SenderEmailAddress)
End Select
inboundemail!From = Left(Chr(34) & .SenderName & Chr(34) & " <" & senderMail & ">", 80)
inboundemail!To = .To
inboundemail!CC = .CC
inboundemail!Subject = Left(.Subject, 80)
inboundemail!DateReceived = .ReceivedTime
inboundemail!uid = .EntryId
SAfeMailItem.Item = objitem
x = SAfeMailItem.SaveAs("c:\temp\" & .EntryId & ".eml", olRFC822)
inboundemail!Size = .Size
inboundemail.Update
End With
End If
Next objitem
Me.ctlDocuments.Requery
Set objitem = Nothing
Set objOutlook = Nothing
Unfortunately the original Mail isn't saved complete
this is the mail in outlook
this is the saved .eml mail
saved eml after 5.23
AS I using the VB6.0 for create a Dialog Box with the ListBox, but only I can get the String text with Trim(DlgText$("xxxxx")), for the other side still I could not found how to get it.
Most of the answer from network said that could be using [LisBox_ID].Selected to get the item that what they want, but I can not get the same result.
For my Code:
[Dialog]
Function aOpenDialog As Boolean
aOpenDialog = False
iArrayLoop = 0
Begin Dialog UserDialog ,,250,120,ScriptTitle,.ActivateDlgControls
Text 5,5,130,10,"Sub Booking End Date", .tf_InsertionSetEndDate
ListBox 5,15,100,100,aArrayList, .aArrayList
Text 110,5,130,10,"After Date [DD-MMM-YYYY]", .tf_AfterDate
TextBox 110,15,55,10, .txt_AfterDate
Text 110,25,55,10,"Change Reason", .tf_ChangeReason
TextBox 110,35,130,10, .txt_ChangeReason
OKButton 110,45,70,10, .btn_Save
CancelButton 110,55,70,10, .btn_Cancel
End Dialog
Dim dlg As UserDialog
aArrayList(1) = "Day1"
aArrayList(2) = "Day2"
Dialog dlg
End Function
[ActiveDlgControls]
Function ActivateDlgControls(ControlName$, Action%, SuppValue%)
If (Action% = 2 And ControlName$ = "btn_Save") Then
sMissingMessage = ""
If (Not IsDate(CStr(Trim(DlgText$("txt_AfterDate"))))) Then
sMissingMessage = sMissingMessage & "- Please input the correct day format"
Else
MsgBox Format(Trim(DlgText$("txt_AfterDate")), "dd mmm yyyy")
' This Area will be using for get the selected array item id
' I can found the selected items with String
MsgBox Trim(DlgText$("aArrayList"))
' Unknow way to found the selected items id
' MsgBox dlg.aArrayList.SelectedItem(x)
End If
If (sMissingMessage <> "") Then
ActivateDlgControls = 1
iCheckResult = 1
sMissingMessage = "Information Missing:" & sMissingMessage
MsgBox sMissingMessage
End If
ElseIf (Action% = 2 And ControlName$ = "btn_Cancel") Then
iCheckResult = 2
End If
End Function
Any idea how should I get the selected ListBox item?
I want to get the array number that I selected inside the LisBox.
Although I got an other stupid idea for get the index like as below code:
For iArrayLoopCheck = 0 To UBound(aArrayList)
If (aArrayList(iArrayLoopCheck) = Trim(DlgText$("aArrayList")))Then
MsgBox "You Select item: " & iArrayLoopCheck
Exit For
End If
Next
Still I was looking for any smart code/ items/ easy way to get the result quickly just like get the String value in array like: Trim(DlgText$("xxxxx"))
Best Regards,
KT
To get the selected index of the list box:
list.ListIndex
returns 0 if the first item is selected, 1 if the second item is selected, etc., and -1 if no item is selected.
I am trying to enumerate the paragraphs selected by the user in (Neo|Libre|Open)Office.
When I use the code below, modified version from here,
Sub CheckForSelection
Dim oDoc as Object
Dim oText
oDoc = ThisComponent
oText = oDoc.Text
if not IsAnythingSelected(oDoc) then
msgbox("No text selected!")
Exit Sub
end if
oSelections = oDoc.getCurrentSelection()
oSel = oSelections.getByIndex(0)
' Info box
'MsgBox oSel.getString(), 64, "Your Selection"
oPE = oSel.Text.createEnumeration()
nPars = 0
Do While oPE.hasMoreElements()
oPar = oPE.nextElement()
REM The returned paragraph will be a paragraph or a text table
If oPar.supportsService("com.sun.star.text.Paragraph") Then
nPars = nPars + 1
ElseIf oPar.supportsService("com.sun.star.text.TextTable") Then
nTables = nTables + 1
end if
Loop
' Info box
MsgBox "You selection has " & nPars & " paragraphs.", 64
end Sub
it finds ALL the paragraphs in the document, not just in the selection. Google has failed me. Any thoughts on how to find individual paragraphs in the selection?
The oSel.Text is a shortcut for oSel.getText() which "Returns the text interface in which the text position is contained." https://www.openoffice.org/api/docs/common/ref/com/sun/star/text/XTextRange.html#getText
So to get a ParagraphEnumeration only from the Selection, you should use oPE = oSel.createEnumeration() instead of oPE = oSel.Text.createEnumeration().
In a sample.csv file, which has fixed number of columns, I have to extract a particular field value and store it in a variable using VBScript.
sample.csv
100,SN,100.SN,"100|SN| 435623| serkasg| 15.32|
100|SN| 435624| serkasg| 15.353|
100|SN| 437825| serkasg| 15.353|"," 0 2345"
101,SN,100.SN,"100|SN| 435623| serkasg| 15.32|
100|SN| 435624| serkasg| 15.353|
100|SN| 437825| serkasg| 15.353|"," 0 2346"
I want to parse the last two fields which are within double quotes and store them in two different array variables for each row.
You could try using an ADO connection
Option Explicit
dim ado: set ado = CreateObject("ADODB.Connection")
ado.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\txtFilesFolder\;Extended Properties=""text;HDR=No;FMT=Delimited"";"
ado.open
dim recordSet: set recordSet = ado.Execute("SELECT * FROM [samples.csv]")
dim field3, field4
do until recordSet.EOF
field3 = recordSet.Fields(3).Value
field4 = recordSet.Fields(4).Value
' use your fields here
recordSet.MoveNext
loop
recordSet.close
ado.close
You may have an issue if those fields are greater than 255 characters in length - if they are, they may return truncated. You also may have better luck with ODBC or ACE connection strings instead of the Jet one I've used here.
Since CSV's are comma-separated, you can use the Split() function to separate the fields into an array:
' Read a line from the CSV...
strLine = myCSV.ReadLine()
' Split by comma into an array...
a = Split(strLine, ",")
Since you have a static number of columns (5), the last field will always be a(4) and the second-to-last field will be a(3).
Your CSV data seems to contain 2 embedded hard returns (CR, LF) per line. Then the first line ReadLine returns is:
100,SN,100.SN,"100|SN| 435623| serkasg| 15.32|
The solution below unwraps these lines before extracting the required fields.
Option Explicit
Const ForReading = 1
Const ForAppending = 8
Const TristateUseDefault = 2 ' Opens the file using the system default.
Const TristateTrue = 1 ' Opens the file as Unicode.
Const TristateFalse = 0 ' Opens the file as ASCII.
Dim FSO, TextStream, Line, LineNo, Fields, Field4, Field5
ExtractFields "sample.csv"
Sub ExtractFields(FileName)
Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FileExists(FileName) Then
Line = ""
LineNo = 0
Set TextStream = FSO.OpenTextFile(FileName, ForReading, False, TristateFalse)
Do While Not TextStream.AtEndOfStream
Line = Line & TextStream.ReadLine()
LineNo = LineNo + 1
If LineNo mod 3 = 0 Then
Fields = Split(Line, ",")
Field4 = Fields(3)
Field5 = Fields(4)
MsgBox "Line " & LineNo / 3 & ": " & vbNewLine & vbNewLine _
& "Field4: " & Field4 & vbNewLine & vbNewLine _
& "Field5: " & Field5
Line = ""
End If
Loop
TextStream.Close()
Else
MsgBox "File " & FileName & " ... Not found"
End If
End Sub
Here is an alternative solution that allows for single or multiline CSV records. It uses a regular expression which simplifies the logic for handling multiline records. This solution does not remove CRLF characters embedded in a record; I've left that as an exercise for you :)
Option Explicit
Const ForReading = 1
Const ForAppending = 8
Const TristateUseDefault = 2 ' Opens the file using the system default.
Const TristateTrue = 1 ' Opens the file as Unicode.
Const TristateFalse = 0 ' Opens the file as ASCII.
Dim FSO, TextStream, Text, MyRegExp, MyMatches, MyMatch, Field4, Field5
ExtractFields "sample.csv"
Sub ExtractFields(FileName)
Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FileExists(FileName) Then
Set MyRegExp = New RegExp
MyRegExp.Multiline = True
MyRegExp.Global = True
MyRegExp.Pattern = """([^""]+)"",""([^""]+)"""
Set TextStream = FSO.OpenTextFile(FileName, ForReading, False, TristateFalse)
Text = TextStream.ReadAll
Set MyMatches = MyRegExp.Execute(Text)
For Each MyMatch in MyMatches
Field4 = SubMatches(0)
Field5 = SubMatches(1)
MsgBox "Field4: " & vbNewLine & Field4 & vbNewLine & vbNewLine _
& "Field5: " & vbNewLine & Field5, 0, "Found Match"
Next
Set MyMatches = Nothing
TextStream.Close()
Else
MsgBox "File " & FileName & " ... Not found"
End If
End Sub