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 » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

If Query Returns No Resluts



 
 
Thread Tools Display Modes
  #1  
Old April 28th, 2009, 10:51 PM posted to microsoft.public.access.forms
Little Penny[_2_]
external usenet poster
 
Posts: 16
Default If Query Returns No Resluts

I have a command button that runs a sql query and load the results in
a form (adapted from Allen Brown). Code work great except when the
query return no results. I get a blank form with no fields. How can I
adapt the code to open a msgbx when the query returns no results or
not found and return me to were I started.


My Code


DoCmd.OpenForm "frmSearchRequestID", , , , , acDialog


If IsLoaded("frmSearchRequestID") Then



GCriteria = Forms![frmGotoRequestID]![cboSearchField] & " = "
& Forms![frmSearchRequestID]![txtSearchString]

'Filter frmCustomers based on search criteria
Form_ frmRequest.RecordSource = "select * from tbl_Request
where " & GCriteria
Form_frmRequest.Caption = "Request Form (" &
Forms![frmSearchRequestID]![cboSearchField].value & " contains '*" &
Forms![frmSearchRequestID]![txtSearchString] & "*')"

'Close frmSearch
DoCmd.Close acForm, "frmSearchRequestID"

MsgBox "Results have been filtered."


End If

End Sub


Thanks



Little Penny
  #2  
Old April 28th, 2009, 11:28 PM posted to microsoft.public.access.forms
Jeanette Cunningham
external usenet poster
 
Posts: 2,190
Default If Query Returns No Resluts

hi Little Penny,
you can do a test to see if there any records matching the criteria.
Below is untested air code--

Dim lngCount as Long
GCriteria = Forms![frmGotoRequestID]![cboSearchField] & " = "
& Forms![frmSearchRequestID]![txtSearchString]

lngCount = DCount("*", "tblRequest", GCriteria)
If lngCount =0 Then
MsgBox "No results"
Else
'the code that opens the search form goes here
End If


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia


"Little Penny" wrote in message
...
I have a command button that runs a sql query and load the results in
a form (adapted from Allen Brown). Code work great except when the
query return no results. I get a blank form with no fields. How can I
adapt the code to open a msgbx when the query returns no results or
not found and return me to were I started.


My Code


DoCmd.OpenForm "frmSearchRequestID", , , , , acDialog


If IsLoaded("frmSearchRequestID") Then



GCriteria = Forms![frmGotoRequestID]![cboSearchField] & " = "
& Forms![frmSearchRequestID]![txtSearchString]

'Filter frmCustomers based on search criteria
Form_ frmRequest.RecordSource = "select * from tbl_Request
where " & GCriteria
Form_frmRequest.Caption = "Request Form (" &
Forms![frmSearchRequestID]![cboSearchField].value & " contains '*" &
Forms![frmSearchRequestID]![txtSearchString] & "*')"

'Close frmSearch
DoCmd.Close acForm, "frmSearchRequestID"

MsgBox "Results have been filtered."


End If

End Sub


Thanks



Little Penny



  #3  
Old April 29th, 2009, 01:13 AM posted to microsoft.public.access.forms
Little Penny[_2_]
external usenet poster
 
Posts: 16
Default If Query Returns No Resluts

That did it

Thank you Jeanette





On Wed, 29 Apr 2009 08:28:44 +1000, "Jeanette Cunningham"
wrote:

Jeanette

 




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


All times are GMT +1. The time now is 10:17 AM.


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