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

Opening Selected Records in a Form Using Code

P: n/a
I would like to open selected (Filtered) records in a form. I
currnetly have a custom menu but would like to only open certain
records from i.e

Button 1 will open Site 1

Button 2 will open Site 2

Etc

I know this can be done using queries but I would rather use code for
this as all the buttons open the same from from the same table. Can
anyone help with this.

Thanks

Craig
Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Look at the Help on the DoCmd.OpenForm -- the WhereCondition argument may do
exactly what you want. You put a base query without criteria as the
RecordSource of the Form, and the WhereCondition or Filter arguments are
used to filter the records.

Larry Linson
Microsoft Access MVP

"Craig Brown" <cr*********@bigfoot.com> wrote in message
news:b3**************************@posting.google.c om...
I would like to open selected (Filtered) records in a form. I
currnetly have a custom menu but would like to only open certain
records from i.e

Button 1 will open Site 1

Button 2 will open Site 2

Etc

I know this can be done using queries but I would rather use code for
this as all the buttons open the same from from the same table. Can
anyone help with this.

Thanks

Craig

Nov 12 '05 #2

P: n/a
Hi there,

You can do this simply in code:

dim crit
crit = "[fieldName]= value"
docmd.openform formName,,crit

crit is inserted in the where attribute of the openform line

you can use all valid sql operators in the criteria statement
ie like, >,<, <> etc etc

if you can be more specific about what you are filtering I don't mind
giving you the code.

:)

"Larry Linson" <bo*****@localhost.not> wrote in message news:<n4*****************@nwrddc03.gnilink.net>...
Look at the Help on the DoCmd.OpenForm -- the WhereCondition argument may do
exactly what you want. You put a base query without criteria as the
RecordSource of the Form, and the WhereCondition or Filter arguments are
used to filter the records.

Larry Linson
Microsoft Access MVP

"Craig Brown" <cr*********@bigfoot.com> wrote in message
news:b3**************************@posting.google.c om...
I would like to open selected (Filtered) records in a form. I
currnetly have a custom menu but would like to only open certain
records from i.e

Button 1 will open Site 1

Button 2 will open Site 2

Etc

I know this can be done using queries but I would rather use code for
this as all the buttons open the same from from the same table. Can
anyone help with this.

Thanks

Craig

Nov 12 '05 #3

P: n/a
Micheal

Thanks for the information, I have tried it but somehow it does not
work, probaly writing the code wrong.

What I am trying to do is use the custom menu that is on a form to open
up a different form. The form I am trying to open is used by several
different sites/locations and tied back to the one table. I would like
the button on the menu to select only that particular site. This way it
would save writing 12 diferent queries. Here is the code I amended to
try

Private Sub DailyRec_Click()
On Error GoTo Err_DailyRec_Click

Dim stDocName As String
' Dim stLinkCriteria As String
Dim crit
stDocName = "DailyRecFrm"
crit = "[Site]=Clyde"
DoCmd.OpenForm "DailyRecFrm", , crit = "[Site]=Clyde"
'DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms![DailyRecFrm].AllowEdits = False
Forms![DailyRecFrm].AllowAdditions = False
Forms!DailyRecFrm!DailyRec2subform.Form.AllowEdits = False
Forms!DailyRecFrm!DailyRec2subform.Form.AllowAddit ions = False
DoCmd.Close acForm, "ViewFrm"
Exit_DailyRec_Click:
Exit Sub

Err_DailyRec_Click:
MsgBox Err.Description
Resume Exit_DailyRec_Click

End Sub

Could you point me in the right direction please.

Thanks in advance

Craig
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.