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  

Form closing problem



 
 
Thread Tools Display Modes
  #1  
Old December 30th, 2006, 02:28 AM posted to microsoft.public.access,microsoft.public.access.forms,microsoft.public.access.formscoding,microsoft.public.access.queries
John
external usenet poster
 
Posts: 409
Default 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  
Old December 30th, 2006, 04:20 AM posted to microsoft.public.access,microsoft.public.access.forms,microsoft.public.access.formscoding,microsoft.public.access.queries
Allen Browne
external usenet poster
 
Posts: 11,706
Default 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  
Old January 1st, 2007, 04:43 PM posted to microsoft.public.access,microsoft.public.access.forms,microsoft.public.access.formscoding,microsoft.public.access.queries
John
external usenet poster
 
Posts: 409
Default 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

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:49 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.