Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pop-up box in form

Status
Not open for further replies.

angiew

Technical User
Jun 22, 2000
37
US
I have a form with multiple combo boxes that allows the user to filter a query.&nbsp;&nbsp;&nbsp;&nbsp;Currently, the users click a button labeled &quot;Selections&quot; that takes them to the Filter by Form window where they make their selections.&nbsp;&nbsp;After the selections are made, they click a button labled &quot;Run&quot;.&nbsp;&nbsp;This &quot;Run&quot; button is actually the &quot;Apply Filter&quot; button from the Filter/Sort toolbar with a different name.&nbsp;&nbsp;There is the possibility that the users could make choices that would result in no records being returned.&nbsp;&nbsp;When this happens, a completely blank form results, and the only option is to close the form and reopen it.&nbsp;&nbsp;I would like to have a dialog box pop up in the case that a user makes choices that result in no records that explains what has happened and will allow them to return to the &quot;Filter by Form&quot; window.&nbsp;&nbsp;I assume that I will need to write some code under the &quot;Apply Filter&quot; button, but I do not know where to access this code because the button is part of the toolbar.&nbsp;&nbsp;I also do not know what code to use.&nbsp;&nbsp;Can anyone help?<br><br>Angie Wenzel<br>
 
you can write this code in the Open event of the form you wanna apply filter to...<br><br>Private Sub Form_Open(Cancel as Integer)<br>&nbsp;&nbsp;&nbsp;Dim MyRs as recordset<br>&nbsp;&nbsp;&nbsp;set MyRs = Me.RecordsetClone<br><br>&nbsp;&nbsp;MyRs.MoveLast<br>&nbsp;&nbsp;MyRs.MoveFirst<br>&nbsp;<br>&nbsp;&nbsp;' if there's no record, Exit<br>&nbsp;&nbsp;if MyRs.RecordCount &lt; 1 Then<br>&nbsp;&nbsp;&nbsp;&nbsp;Msgbox &quot;your msg&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;Cancel = true<br>&nbsp;&nbsp;End If<br>End Sub<br><br>i didnt try it now, but i think it works, Hope this would help YOU... <p>Mohamed Aly<br><a href=mailto:samara_79@hotmail.com>samara_79@hotmail.com</a><br><a href= > </a><br>
 
Thanks for your response!<br><br>I tried your code and got the following error:<br><br>Run-time error '13':<br>Type mismatch<br><br>Then it gave me the option to debug, and the line highlighted by the debugger was:<br><br>set MyRs = Me.RecordsetClone<br><br>Any ideas?<br><br>Angie Wenzel<br>
 
try this<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;Set MyRs = Forms![Formname].Form.RecordsetClone<br> <p>DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br> Ask me how Bar-codes can help you be more productive.
 
Doug,<br><br>I tried your line of code and got the same error with that line still highlighted by the debugger.&nbsp;&nbsp;Any other ideas?<br><br>Angie<br>
 
I think you are using Access 2000, if so you have to make reference to DAO 3,51. then modify the code like the following....<br><br>Private Sub Form_Open(Cancel as Integer)<br>&nbsp;&nbsp;&nbsp;Dim MyRs as DAO.recordset&nbsp;&nbsp;&nbsp;&lt;&lt;&lt; JUST edit this LINE...<br>&nbsp;&nbsp;&nbsp;set MyRs = Me.RecordsetClone<br><br>&nbsp;&nbsp;MyRs.MoveLast<br>&nbsp;&nbsp;MyRs.MoveFirst<br>&nbsp;<br>&nbsp;&nbsp;' if there's no record, Exit<br>&nbsp;&nbsp;if MyRs.RecordCount &lt; 1 Then<br>&nbsp;&nbsp;&nbsp;&nbsp;Msgbox &quot;your msg&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;Cancel = true<br>&nbsp;&nbsp;End If<br>End Sub<br><br>Hope this would help YOU... <p>Mohamed Aly<br><a href=mailto:samara_79@hotmail.com>samara_79@hotmail.com</a><br><a href= > </a><br>
 
Yes, I am using Access 2000.&nbsp;&nbsp;Sorry I didn't specifiy that earlier.&nbsp;&nbsp;I tried the new line of code you posted and got a different error:<br><br>Compile error:<br>User-defined type not defined.<br><br>The debugger highlights the new line of code:<br>MyRs as DAO.recordset<br><br>Any other ideas?<br><br>Angie<br>
 
you are in the right way, but you have missed just one thing that you must make a Reference to DAO 3.51 or DAO 3.6<br><br>1) go to Visual Basic Editor<br>2) chosse Tools, References<br>3) from the dialog box, check &quot;Microsoft DAO 3.51 Object library&quot; or &quot;Microsoft DAO 3.6 Object library&quot;<br>4) now, try again your code<br><br>and let me know if it works or not..... <p>Mohamed Aly<br><a href=mailto:samara_79@hotmail.com>samara_79@hotmail.com</a><br><a href= > </a><br>
 
This took care of the error problems, but now it hasn't changed anything.&nbsp;&nbsp;I still get a blank form and have to completely close it if the selections do not match any records in the query.&nbsp;&nbsp;What am I doing wrong?<br><br>Angie <br>
 
man, could you send your database to my e.mail and i'll take care of it... <p>Mohamed Aly<br><a href=mailto:samara_79@hotmail.com>samara_79@hotmail.com</a><br><a href= > </a><br>
 
I wish I could, but it has sensitive material regarding the company I work for.&nbsp;&nbsp;Besides, I really need to learn how to do this kind of stuff.<br><br>Thanks for all your help!<br><br>Angie<br>
 
Ok, could you tell us what's the RecordSource for your filtered form, and if the filter apply to the form or to the query that the form based on...<br><br>Anyway, i think that your filter apply directly to the form after it got the Records, and that's why our code dosen't work fine. (I mean that the form already has the whole Records from its RecordSource &quot;Table, Query, SQL&quot; and of course our MyRs.RecordCount always greater than 1 )<br><br>In order to make the code works, you have two choices<br>1) apply the filter to a query that the form's RecordSource based on<br>2) set the form's RecordSource = SQL statement which will match your selected filter<br><br>at last you have to delete the following two lines from the code above<br>&nbsp;&nbsp;MyRs.MoveLast<br>&nbsp;&nbsp;MyRs.MoveFirst<br>if your Recordset really dosen't have any records, Access would give you a runtime error about these two line &quot;no current record&quot;. But because your form has records but only filtered it didn't give you that error.<br><br>i hope you could now know what's the wrong and try to work around it, Good Luck<br><br>let me know about your progress, and you are always welcome... <p>Mohamed Aly<br><a href=mailto:samara_79@hotmail.com>samara_79@hotmail.com</a><br><a href= > </a><br>
 
The Record Source for the form is the underlying query.&nbsp;&nbsp;I will explain the database a little more and maybe this will help.&nbsp;&nbsp;The database contains sales information for my company.&nbsp;&nbsp;The sales managers will open the form, allowing them to select filter criteria for a report.&nbsp;&nbsp;They click the
 
*Then it gave me the option to debug, and the line *highlighted by the debugger was:<br>*<br>*set MyRs = Me.RecordsetClone<br><br>You may want to try:<br><br>&nbsp;set MyRs = Me.Recordset.Clone
 
Thanks for the idea, but it didn't change anything.&nbsp;&nbsp;Any other ideas?<br><br>Angie<br>
 
yeah, i got one new idea about your problem. and i'll discuss it now, Suppose you have the following table(this example shows you how you can control your forms, you may change your database to be like this)...<br><br>1) Table1:<br>ID Names &nbsp;&nbsp;&nbsp; City Tel <br>1 Mohamed &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Alex 5012297 <br>2 Ahmed Alex 5021336 <br>3 Mohamed &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Alex 5203645 <br>4 Aly Cairo 2036456 <br><br>2) and &quot;Form1&quot; which has two combo boxes:<br>combo0, RowSource: SELECT DISTINCT [Names] FROM Table1;<br>combo2, RowSource: SELECT DISTINCE [City] FROM Table1;<br>and has one command button (RUN) which opens &quot;Form2&quot;<br><br>3) and &quot;Form2&quot; which its RecordSource: SELECT [Table1].[ID], [Table1].[Names], [Table1].[City], [Table1].[Tel] FROM Table1 WHERE ((([Table1].[Names])=[Forms]![Form1]![Combo0]) And (([Table1].[City])=[Forms]![Form1]![Combo2])); <br>this form has also 4 text boxes for the 4 fields in the above Table1 (ID, Names, City, Tel)<br>and our code:<br>Private Sub Form_Open(Cancel As Integer)<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim MyRs As DAO.Recordset<br>&nbsp;&nbsp;&nbsp;&nbsp;Set MyRs = Me.RecordsetClone<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;If MyRs.RecordCount &lt; 1 Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MsgBox &quot;Your MSG&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cancel = True<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>End Sub<br><br>4) Now, try to run &quot;Form1&quot; and select two values from the combo boxes. Then click &quot;RUN&quot; button in that form. and see what happens. If &quot;Form2&quot; has records it will open, otherwise it will give you a msg and unload...<br><br>Let me know about that... <p>Mohamed Aly<br><a href=mailto:samara_79@hotmail.com>samara_79@hotmail.com</a><br><a href= > </a><br>
 
I appreciate your idea, but my database is huge and it would be rather tedious to change it at this point.&nbsp;&nbsp;I really just need something to fix this one problem.&nbsp;&nbsp;Can you think of anything else?<br><br>Angie<br>
 
Just wanted to let everyone know that I was able to modify a toolbar button to meet my needs.&nbsp;&nbsp;Thanks for all of your help and ideas.&nbsp;&nbsp;Though they didn't meet my needs this time, I learned a lot and may be able to apply them in the future.&nbsp;&nbsp;Thanks to you all!!<br><br>Angie<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top