A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

my search button stop working



 
 
Thread Tools Display Modes
  #1  
Old January 25th, 2005, 05:47 PM
Bessie
external usenet poster
 
Posts: n/a
Default my search button stop working

Hello,

My search button stop working. I had to created a new file because the 1st
one had a corrupt record. This is what i have to activate the search button
in the VBA.

Private Sub cmdSearch_Click()
Dim db As Database, rec As Recordset, lngCount As Long, intRecord As
Integer, rcd As DAO.Recordset
Dim whereAV As String, strOdate As String, strSQL As String
strSQL = "select * from AV Services where AVID"

If Not IsNothing(Me!AVID) Then
whereAV = "[AVID] Like " & Me!AVID
End If

If Not IsNothing(Me!LastName) Then
If IsNothing(whereAV) Then
whereAV = "[CLastName] like " & Chr$(34) & (Me!LastName)
Else
whereAV = whereAV & "AND [CLastName] like " & Chr$(34) &
(Me!LastName)
End If
If Right$(Me!LastName, 1) = "*" Then
whereAV = whereAV & Chr$(34)
Else
whereAV = whereAV & "*" & Chr$(34)
End If
End If

If Not IsNothing(Me!CustomerID) Then
If IsNothing(whereAV) Then
whereAV = "[CFirstName] like " & Chr$(34) & (Me!CustomerID)
Else
whereAV = whereAV & "AND [CfirstName] like " & Chr$(34) &
(Me!CustomerID)
End If
If Right$(Me!CustomerID, 1) = "*" Then
whereAV = whereAV & Chr$(34)
Else
whereAV = whereAV & "*" & Chr$(34)
End If
End If
' ********For request Date*********
If Not IsNothing(Me!Date) Then
If IsNothing(whereAV) Then
whereAV = "[Date] Like " & Chr$(34) & (Me!Date)
Visible = True
Date.ForeColor = vbRed
Else
whereAV = whereAV & "AND [Date] like " & Chr$(34) & (Me!Date)
Date.ForeColor = vbRed
End If
If Right$(Me!Date, 1) = "*" Then
whereAV = whereAV & Chr$(34)
Else
whereAV = whereAV & "*" & Chr$(34)
End If
End If

If Not IsNothing(Me!Entrydate) Then
If IsNothing(whereAV) Then
whereAV = "[EntryDate] Like " & Chr$(34) & (Me!Entrydate)
Else
whereAV = whereAV & "AND [EntryDate] like " & Chr$(34) & (Me!Entrydate)
End If
If Right$(Me!Entrydate, 1) = "*" Then
whereAV = whereAV & Chr$(34)
Else
whereAV = whereAV & "*" & Chr$(34)
End If
End If

If Not IsNothing(Me!Account) Then
If IsNothing(whereAV) Then
whereAV = "[Account] like " & Chr$(34) & Me!Account
Else
whereAV = whereAV & "AND [Account] like " & Chr$(34) & Me!Account
End If
If Right$(Me!Account, 1) = "*" Then
whereAV = whereAV & Chr$(34)
Else
whereAV = whereAV & "*" & Chr$(34)
End If
End If

If Not IsNothing(Me!Department) Then
If IsNothing(whereAV) Then
whereAV = "[Department] like " & Chr$(34) & Me!Department
Else
whereAV = whereAV & "AND [Department] like " & Chr$(34) &
Me!Department
End If
If Right$(Me!Department, 1) = "*" Then
whereAV = whereAV & Chr$(34)
Else
whereAV = whereAV & "*" & Chr$(34)
End If
End If


If Not IsNothing(Me!Start) Then
If IsNothing(whereAV) Then
whereAV = "[start] Like " & Chr$(34) & Me!Start
Else
whereAV = whereAV & "AND [start] " & Chr$(34) & Me!Start
End If
If Right$(Me!Start, 1) = "* " Then
whereAV = whereAV & Chr$(34)
Else
whereAV = whereAV & "*" & Chr$(34)
End If
End If

If IsNothing(whereAV) Then
MsgBox "No criteria specified.", 32
Exit Sub
End If
Me.Visible = False
' Hide myself and turn on Hourglass
DoCmd.Hourglass True
If IsLoaded("AVSummary") Then ' If AV form already open, Then just
filter it
Forms!AVForm.SetFocus
DoCmd.ApplyFilter , whereAV
If Forms![AVForm].RecordsetClone.RecordCount = 0 Then
DoCmd.Hourglass False
MsgBox "No Record meet your criteria 1st message", 64
DoCmd.ShowAllRecords
Forms!AVForm!CmdAddNew.Visible = True
Forms!AVForm!CmdShowAll.Visible = False

Exit Sub
End If
DoCmd.Hourglass False
Forms!AVForm!CmdAddNew.Visible = False
Forms!AVForm!CmdShowAll.Visible = True
Else
' Find out if any Record satisfy the Where clause
Set db = CurrentDb
Set rec = db.OpenRecordset("AV Services")
' If none found, then tell them and make me visible to try again
If rec.RecordCount = 0 Then
DoCmd.Hourglass False
MsgBox "No AV Record meet your criteria", vbInformation
whereAV = " "
Me!Visible = True
rec.Close
Exit Sub
End If
' Move to last row to get an accurate record count
rec.MoveLast
lngCount = rec.RecordCount
DoCmd.Hourglass False
' If more than 5, then ask if they want to see a summary
If lngCount = 5 Then
intRecord = MsgBox("Would you like to review this record?,",
vbInformation + vbOKCancel)

Select Case intRecord
Case vbCancel ' Cancel - Try again
Me.Visible = True
Exit Sub
Case vbYes ' Yes - show summary form
DoCmd.OpenForm FormName:="AVSummary",
wherecondition:=whereAV
DoCmd.Close acForm, Me.Name
Forms!AVsummary.SetFocus
Exit Sub
End Select
End If
' Replied NO or not more than 2, show full details
DoCmd.OpenForm FormName:="AVSummary",
wherecondition:=whereAV

End If
DoCmd.Close acForm, Me.Name
' Close me, and we're done Yeah

End Sub
Once again it was working fine until I created a new file, how can I
simplify this?
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help - Why did my vis basic formula stop working Kevin Worksheet Functions 2 February 19th, 2004 04:53 PM


All times are GMT +1. The time now is 04:34 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.