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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Form closing problem
Hi
I have a form with a list box. The list box is bound to a query which has below as the parameter; [Forms]![MyForm]![Client] [Client] is a drop down on the same form. So when a user selects a client the listbox displays the relevant records for the client. This works fine. The problem is that when I try to close the form by clicking on a button which has the below code; DoCmd.Close acForm, Me.Name I get a dialog that says 'Enter Parameter Value' and the value it is asking for is for [Forms]![MyForm]![Client]. How can I get rid of this message while successfully being able to close the form via code? Thanks Regards |
#2
|
|||
|
|||
Form closing problem
This problem occurs because of the cyclic dependencies between the form and
its controls and the query. The solution is to find another approach that removes those dependencies. One solution is to remove the criteria from the query. Instead use the AfterUpdate event of the combo to create the query string, and assign it to the list box. This example assumes that: - the Client combo is unbound; - the Bound Column of the combo is the primary key of the Clients table, and that's a numeric field. Private Sub Client_AfterUpdate() Dim strSql As String strSql = "SELECT ClientID, ClientName FROM Clients WHERE (" If IsNull(Me.Client) Then strSql = strSql & "False" Else strSql = strSql & "ClientID = " & Me.Client End If strSql = strSql & ") ORDER BY ClientName, ClientID;" 'Debug.Print strSql Me.List1.RowSource = strSql End Sub If you need help getting the SQL string correct, switch you query to SQL View (View menu in query design) for an example. -- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "John" wrote in message ... I have a form with a list box. The list box is bound to a query which has below as the parameter; [Forms]![MyForm]![Client] [Client] is a drop down on the same form. So when a user selects a client the listbox displays the relevant records for the client. This works fine. The problem is that when I try to close the form by clicking on a button which has the below code; DoCmd.Close acForm, Me.Name I get a dialog that says 'Enter Parameter Value' and the value it is asking for is for [Forms]![MyForm]![Client]. How can I get rid of this message while successfully being able to close the form via code? |
#3
|
|||
|
|||
Form closing problem
I have done this with many forms before. Not sure why the problem cones with
only this one. Thanks Regards "Allen Browne" wrote in message ... This problem occurs because of the cyclic dependencies between the form and its controls and the query. The solution is to find another approach that removes those dependencies. One solution is to remove the criteria from the query. Instead use the AfterUpdate event of the combo to create the query string, and assign it to the list box. This example assumes that: - the Client combo is unbound; - the Bound Column of the combo is the primary key of the Clients table, and that's a numeric field. Private Sub Client_AfterUpdate() Dim strSql As String strSql = "SELECT ClientID, ClientName FROM Clients WHERE (" If IsNull(Me.Client) Then strSql = strSql & "False" Else strSql = strSql & "ClientID = " & Me.Client End If strSql = strSql & ") ORDER BY ClientName, ClientID;" 'Debug.Print strSql Me.List1.RowSource = strSql End Sub If you need help getting the SQL string correct, switch you query to SQL View (View menu in query design) for an example. -- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "John" wrote in message ... I have a form with a list box. The list box is bound to a query which has below as the parameter; [Forms]![MyForm]![Client] [Client] is a drop down on the same form. So when a user selects a client the listbox displays the relevant records for the client. This works fine. The problem is that when I try to close the form by clicking on a button which has the below code; DoCmd.Close acForm, Me.Name I get a dialog that says 'Enter Parameter Value' and the value it is asking for is for [Forms]![MyForm]![Client]. How can I get rid of this message while successfully being able to close the form via code? |
Thread Tools | |
Display Modes | |
|
|