Full Version: How to open a specific record in a form...
UtterAccess Forums > Microsoft® Access > Access Forms
I am trying to open a form and opening that form with a specific record... I am going this by hitting a command button.
This is what I have, but it is not working like I want.
Any Ideas?>
I am trying to open "frmIndividualReport" where jurornumber (a field in my table) is equal to the number 16
DoCmd.OpenForm "frmIndividualReport", , "[jurornumber] = '16'"
Is jurornumber a numeric field.If so
DoCmd.OpenForm "frmIndividualReport", , , "[jurornumber] =16" may work
I think one comma is missing and extra quote not needed for 16 in your command
If the limiting field in on the form with the command button, the command button wizard will actually write the code for you!
Ok, I think that is correct, but I think I need to call the table because I am getting an error.
omething like this but I am sure this is wrong?
DoCmd.OpenForm "frmIndividualReport", , , "tblMain [jurornumber] =16"
Thanks for the help!
Any Ideas?
Howdy Stranger! o!
Hope all's well Chance - been a while!
Ok, first off is there a field in the recordsource of the form you want to open named 'jurornumber' ?
Is this form 'filterable' (Allowfilters = yes) ?
If so you can do this and it should work:
DoCmd.OpenForm "frmIndividualReport", , , "jurornumber = 16"
Strikes me odd you'd 'hardcode' the juror number. I'd figure you'd be selecting your filter (or where condition), from a list or combo. Code for something like this would be:
DoCmd.OpenForm "frmIndividualReport", , , "jurornumber = " & Me.NameOfYourListOrComboBoundColumnOrColumnNumberZeroBased
What's the error you're receiving?
Gord (Sylvie says hi! -o! )
Here is the deal... the person I am doing this for wants a series of command buttons in a row of 66 (representing 66 jury members.
They want to be able to click on the command button and have it bring up that jurors information.
to answer your questions,
yes the jurornumber field is on the form
Allowfilters is set to yes
The error is a run-time error '2501'
Any Ideas?
Sure miss you guys!
Should work. Do you perhaps have the juror number listed twice in the record source? If so then you will need to either remove the duplicate or as you tried, refer to the field prefixed with the correct table name.
That you might need to do is like this:
DoCmd.OpenForm "frmIndividualReport"
DoCmd.RunCommand acCmdRemoveFilterSort '<<<<< clear off any old stuck filters
DoCmd.ApplyFilter , "JurorNumber = 16"
See what happens with this please?
Gord o!
It is getting hung up on this right here...
oCmd.ApplyFilter , "JurorNumber = 16"
Ochecked and there are no duplicates?
What's the error say - can you copy / paste in your recordsource ?
Run-time error '2501':
The ApplyFilter action was canceled
When I try to filter manually I get a "data type mismatch in criteria expression"
Never mind on that last error "data type mismatch in criteria expression"
I was doing the manual filter wrong.
I am able to filter correctly inside the form I am wanting to filter...
Any Ideas>?
Ok, so your "16" is a string... not a real number then, correct?
oCmd.ApplyFilter , "JurorNumber = '16'"
nreal yet again!
I guess I need to change the field from text to a number field correct?
Thanks a TON man!!
Well, it would probably be wise if you know you'll always be using numbers to designate jurors. Then of course you can toss the single quotes.
Glad to help Chance - my pleasure!
Gord thumbup.gif
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.