Tip

Search a database using a customized form

Here's a LotusScript solution for searching your database using a
customized Search form (i.e. to search for values by certain fields
or a combination of fields.)

The script also displays the results in a 'private on first use' folder.

This script is placed in a button on the Search form. The
fieldnames in the search form are identical to the fieldnames in my
default "Bug" form.

The search form when closed 'disappears' into a hidden view, so it
acts like a search template.

Sub Search
Dim workspace As NotesUIWorkspace
Dim uidb As NotesUIDatabase
Dim session As  NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim view As NotesView
Dim doc As NotesDocument
Dim uidoc As NotesUIDocument
Dim searchFormula As String

	On Error Goto processError	

	Set workspace = New NotesUIWorkspace
	Set session = New NotesSession
	Set uidb = workspace.CurrentDatabase		
	Set uidoc = workspace.CurrentDocument
	Set db = session.CurrentDatabase
	
	Call uidoc.Refresh
	
	Call uidoc.Save	
	foldername1$ = "Results"
	
'Base formula.---------------------------------------------	
	searchFormula = "Form= ""Bug""" 	
'----------------------------------------------------------------
	
	'--------------search fields------------------------------------
	t_Type$ = uidoc.FieldGetText("Type")		
	t_EnterBy$ = uidoc.FieldGetText( "EnterBy" )
	t_DateEntered$ = uidoc.FieldGetText("DateEntered")
	t_DateEntered_1$ = uidoc.FieldGetText("DateEntered_1")
	t_Software$ = uidoc.FieldGetText("Software")
	t_RelatedHardware$ = uidoc.FieldGetText("RelatedHardware")
	t_RelatedOptions$ = uidoc.FieldGetText("RelatedOptions")
	t_Customer$ = uidoc.FieldGetText("Customer")
	t_BugTitle$ = uidoc.FieldGetText("BugTitle")
	t_Status$ = uidoc.FieldGetText("Status")
	t_QCOwner$ = uidoc.FieldGetText("QCOwner")
	t_FixOwner$ = uidoc.FieldGetText("FixOwner")
	t_DateClosed$ = uidoc.FieldGetText("DateClosed")
	t_DateClosed_1$ = uidoc.FieldGetText("DateClosed_1")	
	
	'-------------conditions-----------------------------------------
	
	If t_EnterBy$ <> "" Then
		t_EnterBy$ = " & @Contains(EnterBy;'" & t_EnterBy$ & "') "				
		searchFormula = searchFormula & t_EnterBy$
	Else
		'Do nothing		
	End If
	
	Select Case t_Type$
	Case "Pre-Release QC"  
		t_Type$ =" & Type = 'QC' "
		searchFormula = searchFormula & t_Type$
	Case "Customer (Post Release)"
		t_Type$ =" & Type = 'Customer' "
		searchFormula = searchFormula & t_Type$
	Case "Feature Request"
		t_Type$ =" & Type = 'Feature Request' "
		searchFormula = searchFormula & t_Type$
	End Select
	
	If t_DateEntered$ <> "" And t_DateEntered_1$ ="" Then
t_DateEntered$ = " & DateEntered = [" & t_DateEntered$
& "]" searchFormula = searchFormula & t_DateEntered$ Elseif t_DateEntered$ <> "" And t_DateEntered_1$ <> "" Then t_DateEntered$ = " & DateEntered >= [" &
t_DateEntered$ & "] & DateEntered <= [" &
t_DateEntered_1$ & "]" searchFormula = searchFormula & t_DateEntered$ Elseif t_DateEntered$ = "" Then 'Do nothing End If If t_Software$ <> "" Then t_Software$ = " & @Contains(Software;'" & t_Software$ & "') " searchFormula = searchFormula & t_Software$ Else 'Do nothing End If If t_RelatedHardware$ <> "" Then t_RelatedHardware$ = " & @Contains(RelatedHardware;'" &
t_RelatedHardware$ & "') " searchFormula = searchFormula & t_RelatedHardware$ Else 'Do nothing End If If t_RelatedOptions$ <> "" Then t_RelatedOptions$ = " & @Contains(RelatedOptions;'" &
t_RelatedOptions$ & "') " searchFormula = searchFormula & t_RelatedOptions$ Else 'Do nothing End If If t_Customer$ <> "" Then t_Customer$ = " & @Contains(Customer;'" & t_Customer$ & "') " searchFormula = searchFormula & t_Customer$ Else 'Do nothing End If If t_BugTitle$ <> "" Then t_BugTitle$ = " & @Contains(BugTitle;'" & t_BugTitle$ & "') " searchFormula = searchFormula & t_BugTitle$ Else 'Do nothing End If If t_Status$ <> "" Then t_Status$ = " & @Contains(Status;'" & t_Status$ & "') " searchFormula = searchFormula & t_Status$ Else 'Do nothing End If If t_QCOwner$ <> "" Then t_QCOwner$ = " & @Contains(QCOwner;'" & t_QCOwner$ & "') " searchFormula = searchFormula & t_QCOwner$ Else 'Do nothing End If If t_FixOwner$ <> "" Then t_FixOwner$ = " & @Contains(FixOwner;'" & t_FixOwner$ & "') " searchFormula = searchFormula & t_FixOwner$ Else 'Do nothing End If If t_DateClosed$ <> "" And t_DateClosed_1$ ="" Then t_DateClosed$ = " & DateClosed = [" & t_DateClosed$ & "]" searchFormula = searchFormula & t_DateClosed$ Elseif t_DateClosed$ <> "" And t_DateClosed_1$ <> "" Then t_DateClosed$ = " & DateClosed >= [" & t_DateClosed$
& "] & DateClosed <= [" & t_DateClosed_1$ & "]" searchFormula = searchFormula & t_DateClosed$ Elseif t_DateClosed$ = "" Then 'Do nothing End If '____________________________________________________________________ Print "Searching..... " & searchFormula & " " Set dc = db.Search(searchFormula, Nothing, 0) If dc.Count <> 0 Then For i=1 To dc.Count Set doc = dc.GetNthDocument(i) '... downloading processing ... Call doc.PutInFolder( folderName1$ ) doc.searchFormula = searchFormula Call doc.Save(True,False) Next 'Send User to Results Folder Messagebox "Bugs Found: " & Cstr(dc.Count),, "Search Results" Call workspace.OpenFrameSet( "MainFS2" ) Call workspace.SetTargetFrame( "Right" ) Call uidb.OpenView( foldername1$ ) Else Messagebox "No Bugs Found" End If Call uidoc.Close Exit Sub processError: '4412 captures Status field error. If Err = 4412 Then Exit Sub '4291 means no Private folder exists. Elseif Err = 4291Then msg1$="You need to create a private (Results) folder before doing a Search." msg2$="Please click on the 'Results' folder to create it." Messagebox msg1$ & Chr(13) & msg2$ ,,"Error" Call uidoc.Close Exit Sub Else Messagebox "Error Msg: " & Error,,"Contact Admin" & "-" & "[" & Err & "]" End If Exit Sub End Sub

This was first published in June 2002

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.