Problem with the button on the form

fijufiic

Registered User.
Local time
Today, 15:05
Joined
Mar 19, 2008
Messages
20
Hi,

Could someone please let me know what I'm doing wrong?

I have a form, which uses a query to show only records labeled as "Draft" - and that works. On the form, I want to build the button, which would be connected to another query and when clicked only records labeled as "Final" would be displayed.

Here is the code for the button:

DoCmd.OpenQuery "FinalRecords", acViewNormal, acReadOnly

I'm not sure if I need anything else to add to above code in order to make this button working.

Any suggestion is appreciated.

Thanks,

-f
 
I would use a combo box to select either Draft or Completed and use that as the criterion for the query. Use the After Update event of the combo to requery the form.
 
I would use a combo box to select either Draft or Completed and use that as the criterion for the query. Use the After Update event of the combo to requery the form.

Yes, I do have a combo box and I could query from the selection in the combo box in the similar way I currently control submission of the records. I would really like to have a button that will pull out only the "Final" records. I wonder why my code for the button is not working. I know that query, when run alone, works and pulls correct records... Any suggestions?

Thank you,

-f
 
Is the 'final' criterion hard coded in the query? Can you post the SQL?
 
Is the 'final' criterion hard coded in the query? Can you post the SQL?

Basically, I created a query in Access which includes the fields on the form that I would like to display (approximately 7 fields) when I click the button on the form. This query includes Status field (with Criteria: "Final") and IA Number field (with Criteria: [Enter IA Number]).

Then, created a button on the form and went to the button properties to build the event for this button and below is the VB code:

Private Sub FinalStatus_Click()
DoCmd.OpenQuery "FinalComments", acViewNormal, acReadOnly
End Sub

I tried without specifying the ViewNormal and ReadOnly properties and it still does not work.

Hope I provided you with enough information.

Thank you,

-f
 
Actually, your code looks fine; I assume that the query name is spelled correctly.

Some questions:

What version/service pack of Access are you running?

Do you have other buttons in your db that work?

How, exactly, did you enter the code for your button?

In Design View, if you select the button, then goto Properties - Event does the Click property say [Event Procedure]?
 
Actually, your code looks fine; I assume that the query name is spelled correctly.

Some questions:

What version/service pack of Access are you running?

Do you have other buttons in your db that work?

How, exactly, did you enter the code for your button?

In Design View, if you select the button, then goto Properties - Event does the Click property say [Event Procedure]?

Hi missinglinq,

The query name is spelled correctly - I checked multiple times;
I'm working in MS Access 2007 (& I do not like it for many reasons);
I do have other working buttons on my form but none of those are dealing with the queries;
In design view of my form, I created a button and right clicked on it and selected "build event". Then I selected Code and entered the code for the button that I copied in my previous post.
Yes, when I'm in design view and select properties for the button, the Click property says [Event Procedures];

Hope I answered all your questions. I really do not know what could be wrong and why the button would not work.

Thank you,

-f

P.S. I tried creating a macro, instead of coding, for a click property of the button. It works, but with macro I'm only able to open "Final" comments in the table format -- it does not allow me to load them into the Form format.
 
Is the query not opening?

I have a similar button and it works for me
my line of code is
Code:
 DoCmd.OpenQuery "cstfrmjoinqry", acViewDesign, acEdit
this opens it up so I can select the criteria .

However after I save it and close the query I have to close the form and reopen in order to get the filtered results.

I have a issue posted on this forum.
 
Try in the OnClick event of your Command Button:

Me.RecordSource = "yourQueryName"

.
 
That got me in trouble. Not that I needed any.

What happens when you need to change it back?

You would have to have another back to have it go back the orginal?

But is the problem that the onclick is not opening the query?

I'm not the right person to be offering advice or solutions. I have too many as it is.:o
 
Hi everyone,

Thank you for replying.

cardgunner, I tried the code you suggested but my button is still dead. Again, if I use macro instead of the code, I can pull the data I want but it will appear in the table format rather than within the form.

CyberLynx, I will try your suggestion once I get back to the office tomorrow morning and let you know if it worked.

Side note: My form is directly linked to the query which filters records based on the field. The button, which I cannot get to work, should link to another query (different from the one linked directly to the form) and look for records not queried by the query linked to the form. I wonder if that has anything to do with the problem I'm experiencing. Maybe the button query is not able to override the form query. What you guys think?

Best,

-f
 
Try in the OnClick event of your Command Button:

Me.RecordSource = "yourQueryName"

.

I tried your suggestion - and my button is still dead!

Hmmm... I do not know why my button won't work! It's so frustrating.

-f
 
I tried your suggestion - and my button is still dead!

Hmmm... I do not know why my button won't work! It's so frustrating.

-f
Can you post your database here so we can look for the problem.
 
do you mean your FORM is bound to a query, and you want it to be bound to a different query

in that case you want

me.recordsource = "whicheverquery"
me.requery
 
do you mean your FORM is bound to a query, and you want it to be bound to a different query

in that case you want

me.recordsource = "whicheverquery"
me.requery

Yes, my form is bound to a query and I would like to have a button that runs another query (this query would not be bound to the form - it would run on click of the button on the form).

Hope I did not confuse you.

-f
 
cardgunner, I tried the code you suggested but my button is still dead. Again, if I use macro instead of the code, I can pull the data I want but it will appear in the table format rather than within the form.
-f

You are using this code in the onclick event of the button?

Have you tried deleteing the button and create a new one?

the macro that works is it the openquery macro?
You set it to your query name set the view to what? Set the data mode to what?

Strange.

I did get me problem solved with the help ajtrumpet and cyberlynx.

Hopefully I can pay forward the efforts from them.
 
You are using this code in the onclick event of the button?

Have you tried deleteing the button and create a new one?

the macro that works is it the openquery macro?
You set it to your query name set the view to what? Set the data mode to what?

Strange.

I did get me problem solved with the help ajtrumpet and cyberlynx.

Hopefully I can pay forward the efforts from them.


It is strange :) Only coded buttons on my form do not work - my code is possessed :D

I have deleted and re-created the button many many times - same result.
And yes, the macro works fine - I just don't like that the records are pulled in the table rather than the form itself.

Could there be any property on the form that needs to be changed?

Thank you all for your input on my very strange problem.

-f
 
It is strange :) Only coded buttons on my form do not work - my code is possessed :D
-f

Do you have other forms bith command buttons on them? And do they work there?

Have you tried to redo the form you are using?

I have not heard of any form property that could get inadvertanly switched so code would not work.

I'm not an expert at this so I'm just offering things i might try.
 
Do you have other forms bith command buttons on them? And do they work there?

Have you tried to redo the form you are using?

I have not heard of any form property that could get inadvertanly switched so code would not work.

I'm not an expert at this so I'm just offering things i might try.

I have other forms and I tried creating buttons on those forms - if the button is coded, it does not work.

I'm not sure if re-doing the form(s) would help me -- it seems that I would have to re-do the whole project which, of course, I do not want to do.

cardgunner, what version of Access are you running? I'm working in 2007, and I'm almost convinced that is part of my problem.

Thank you for your suggestions.

-f
 

Users who are viewing this thread

Back
Top Bottom