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

Simple ? on VBA (I hope)

P: n/a
OM
Can someone tell me why, in Event Procedures that are generated by MS
Access, (say to open a form, as below), the form name is entered as a
variable stDocName. Why not just use the form name itself ? Or is there a
good reason not to? I would guess the same arguments apply to stLinkCriteria
?

ie why

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmIncidentHeader"
DoCmd.OpenForm stDocName, , , stLinkCriteria
rather than

DoCmd.OpenForm frmIncidentHeader, , , fldQNIEV=100
Thanks folks

Rob Lepper
Jan 13 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
There is no need to create variables for these simple examples.

But it might be a good idea. Sometimes you want to add more code that refers
to the form once it's open, so you can do that with:
Forms(stDocName)

Other times, the criteria can get quite complex (several clauses, even
subqueries that look up values in tables that are not in the form's
RecordSource). You can simplify the debugging process by adding the line:
Debug.Print stLinkCriteria

My personal preference is that I use a variable for the WhereCondition most
of the time, but only use one for the form name if I will refer to it more
than once.

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

"OM" <OM@youknowwhere.comwrote in message
news:45**********************@news.optusnet.com.au ...
Can someone tell me why, in Event Procedures that are generated by MS
Access, (say to open a form, as below), the form name is entered as a
variable stDocName. Why not just use the form name itself ? Or is there a
good reason not to? I would guess the same arguments apply to
stLinkCriteria ?

ie why

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmIncidentHeader"
DoCmd.OpenForm stDocName, , , stLinkCriteria
rather than

DoCmd.OpenForm frmIncidentHeader, , , fldQNIEV=100
Thanks folks

Rob Lepper
Jan 13 '07 #2

P: n/a
OM
Thanks Allen. I thought that maybe it was something like that, but wasn't
sure.

Rob Lepper

"Allen Browne" <Al*********@SeeSig.Invalidwrote in message
news:45***********************@per-qv1-newsreader-01.iinet.net.au...
There is no need to create variables for these simple examples.

But it might be a good idea. Sometimes you want to add more code that
refers to the form once it's open, so you can do that with:
Forms(stDocName)

Other times, the criteria can get quite complex (several clauses, even
subqueries that look up values in tables that are not in the form's
RecordSource). You can simplify the debugging process by adding the line:
Debug.Print stLinkCriteria

My personal preference is that I use a variable for the WhereCondition
most of the time, but only use one for the form name if I will refer to it
more than once.

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

"OM" <OM@youknowwhere.comwrote in message
news:45**********************@news.optusnet.com.au ...
>Can someone tell me why, in Event Procedures that are generated by MS
Access, (say to open a form, as below), the form name is entered as a
variable stDocName. Why not just use the form name itself ? Or is there a
good reason not to? I would guess the same arguments apply to
stLinkCriteria ?

ie why

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmIncidentHeader"
DoCmd.OpenForm stDocName, , , stLinkCriteria
rather than

DoCmd.OpenForm frmIncidentHeader, , , fldQNIEV=100
Thanks folks

Rob Lepper

Jan 13 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.