By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,652 Members | 1,995 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,652 IT Pros & Developers. It's quick & easy.

OpenForm WhereCondition not working

P: 40
I have been stuck for some time on this now.
I have this code at the moment
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "Form1", , , "Apps= '" & Form!App_Name & "'"
  2.  
Both fields Apps and App_Name are Bound to the same field (text) which is primary key. With the current code I get box where it asks for value of Apps. I have tried changing where condition in different ways, also with me.App_Name but with no result. On some debugs it shows that it finds the right value but it just don't use it! It works fine if I enter the value in the box or write it in hard code: Apps = XXXXX.
I am using Access 2000.
Any ideas what could be the problem?
Oct 5 '07 #1
Share this Question
Share on Google+
13 Replies


nico5038
Expert 2.5K+
P: 3,072
Hmm, puzzled why you have two fields bound to the same field.
Normally when this is the case, one field will be named "Apps" and the other e.g. "Text1" as Access won't allow two fields on a form to have the same name.

The popup asking for the "Apps" value is an indication that the field "Apps" isn't found, thus you'll need to check the names of the formcontrols (See the Name property under the "Other" tab of the property window.)

Nic;o)
Oct 5 '07 #2

P: 40
Sorry I must have explained it badly.

The button is locates on the form called List1 and has a field called App_Name. So when the button is pressed I want it to open a form called Form1 in which field Apps should display the same value as was in App_Name. They both are bound to the same field in table but they are on different forms.
The names I am using are correct, I have double checked all of them...
Oct 5 '07 #3

Jim Doherty
Expert 100+
P: 897
Sorry I must have explained it badly.

The button is locates on the form called List1 and has a field called App_Name. So when the button is pressed I want it to open a form called Form1 in which field Apps should display the same value as was in App_Name. They both are bound to the same field in table but they are on different forms.
The names I am using are correct, I have double checked all of them...

Expand|Select|Wrap|Line Numbers
  1.  
  2. DoCmd.OpenForm "Form1", , , "Apps= '" & Me!App_Name & "'"
  3.  
Oct 5 '07 #4

P: 40
Expand|Select|Wrap|Line Numbers
  1.  
  2. DoCmd.OpenForm "Form1", , , "Apps= '" & Me!App_Name & "'"
  3.  
Tried that... still asks to enter value for Apps.... tried also with me.App_name. I tried also some with setting Me!App_Name/Form!App_Name as a seperate criteria and debugger showed that it recognizes the value but it was not using it...
Oct 5 '07 #5

Jim Doherty
Expert 100+
P: 897
Tried that... still asks to enter value for Apps.... tried also with me.App_name. I tried also some with setting Me!App_Name/Form!App_Name as a seperate criteria and debugger showed that it recognizes the value but it was not using it...
Are you sure you are mixing up your table field names and control names here? the Do.cmd.OpenForm command I posted is syntactically correct.

Check that your table field names and Control Names match ie NOT where you have the NAME of a control as Apps on Form1 make sure it is the same as the controlsource and try it again.

When you make a call like that to "Apps" it is expecting 'Apps' to be a field name in the underlying table on which to base its SQL comparison if you do not have a TABLE field called explicitly 'Apps' then this is why is will prompt you because the field doe not exist

Jim
Oct 5 '07 #6

nico5038
Expert 2.5K+
P: 3,072
Check form1 for the field you assume to be "Apps" by checking the Name property under the "Other" tab of the property window when the "Apps" control is "active" in design mode.

Nic;o)
Oct 5 '07 #7

P: 40
OK here is what I have:
List_1 - form which contains text box - App_Name (control source - Interface)
there is also the button with which I want to open form - Form1
On Form1 there is also a text field called Apps (control source - Interface)
So I want after the click to open Form1 where in Apps text box will be the same value as App_Name in List_1 form.
Also I was looking through the code and found some code, which I believe was auto generated and I am not using but seems to be for similar purpose.
Expand|Select|Wrap|Line Numbers
  1. stLinkCriteria = "[To]=" & "'" & Me![App_Name] & "'"
  2.  
Hope this helps
Oct 5 '07 #8

nico5038
Expert 2.5K+
P: 3,072
OK here is what I have:
List_1 - form which contains text box - App_Name (control source - Interface)
there is also the button with which I want to open form - Form1
On Form1 there is also a text field called Apps (control source - Interface)
So I want after the click to open Form1 where in Apps text box will be the same value as App_Name in List_1 form.
Also I was looking through the code and found some code, which I believe was auto generated and I am not using but seems to be for similar purpose.
Expand|Select|Wrap|Line Numbers
  1. stLinkCriteria = "[To]=" & "'" & Me![App_Name] & "'"
  2.  
Hope this helps
Try this:
1) Open "Form1" in design mode.
2) Single click on the field "Apps"
3) Press Properties button (Hand with white sheet)
4) In properties window under the "Other" tab look into the first propertyline (Name) and tell what's listed there.

Nic;o)
Oct 5 '07 #9

P: 40
Good.... got it working sort of... needed to use control source... I did not know that, so now it filters only to selected record.

Thanks Jim and Nico...

But it seems that I need something a bit more complicated then that for my other form.
On the third form I have unbound list box, which has the same control source as previous. And I have a Subform. So how do I filter the subform while still having full list in the list box? alternately could also just make selection in list box.

Thanks again for explaining to use control source and hope you can help o this as well...
Oct 5 '07 #10

nico5038
Expert 2.5K+
P: 3,072
When you use the wizard to place the subform, it will ask for a linking field. Just accept the proposed field and Access will sync the subform with the keyvalue of the mainform.
When the mainform is filtered, the subform will also be filtered accordingly.

Nic;o)
Oct 5 '07 #11

P: 40
That is the thing. I did not use wizard for that... I linked the subform to the listbox on the main form. and the listbox in not bound. Listbox is there purely for selection purpose which then filters the subform. The main form does not even have a Record Source or anything like that...
If that is too complicated or requires me to change a lot... then don't worry.. #Got at least some of it working thanks to you... should be good enough...
Oct 5 '07 #12

nico5038
Expert 2.5K+
P: 3,072
OK, but here is a link to a sample of the Object/Action principle I use for creating forms and allow the user to select record(s) before applying the action:
http://www.geocities.com/nico5038/xS...tAction-97.zip
for the filtering of the datasheet subform I give my users:
http://www.geocities.com/nico5038/xR...nstruction.zip
perhaps it gives some additional insights.

Nic;o)
Oct 5 '07 #13

P: 40
Thanks...
I will have a look at those on Monday... Time for me to finish off the working say
Appreciate you help!!!
Oct 5 '07 #14

Post your reply

Sign in to post your reply or Sign up for a free account.