G
Guest
i have been VBA programming for a while now, and i have noticed that i do a
lot of things multiple times over and over again.
for instance, the whole thing of opening a form to find a related record.
the code usually goes like this:
Private Sub lstIssue_DblClick(Cancel As Integer)
On Error GoTo Err_cmdIssueForm_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmManageIssues"
stLinkCriteria = "[IssueID]=" & Me![lstIssue]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_cmdIssueForm_Click:
Exit Sub
Err_cmdIssueForm_Click:
MsgBox Err.Description
Resume Exit_cmdIssueForm_Click
End Sub
now i am wondering, is there a way to make a routine that would do it for
any button i decide to call it. i think that a routine to do that would be
very complicated because it would have to know the linking criteria for each
form and related for combination. the example i gave has this line:
stLinkCriteria = "[IssueID]=" & Me![lstIssue], but on other forms where i
have a similar button the criteria would be some 2 controls on each form that
are different.
is there any catch all routine that would be able to figure it out for any
form and related forms? and if there was would it be benificial to do it with
a global routine that figured it out and then opened the appropriate forms
with the appropriate link criteria? would this make my database smaller, more
effcient and faster?
second, would it be benificial to globably dim the variables used in this
code? again the same question applies, would it make my database better?
lot of things multiple times over and over again.
for instance, the whole thing of opening a form to find a related record.
the code usually goes like this:
Private Sub lstIssue_DblClick(Cancel As Integer)
On Error GoTo Err_cmdIssueForm_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmManageIssues"
stLinkCriteria = "[IssueID]=" & Me![lstIssue]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_cmdIssueForm_Click:
Exit Sub
Err_cmdIssueForm_Click:
MsgBox Err.Description
Resume Exit_cmdIssueForm_Click
End Sub
now i am wondering, is there a way to make a routine that would do it for
any button i decide to call it. i think that a routine to do that would be
very complicated because it would have to know the linking criteria for each
form and related for combination. the example i gave has this line:
stLinkCriteria = "[IssueID]=" & Me![lstIssue], but on other forms where i
have a similar button the criteria would be some 2 controls on each form that
are different.
is there any catch all routine that would be able to figure it out for any
form and related forms? and if there was would it be benificial to do it with
a global routine that figured it out and then opened the appropriate forms
with the appropriate link criteria? would this make my database smaller, more
effcient and faster?
second, would it be benificial to globably dim the variables used in this
code? again the same question applies, would it make my database better?