我该如何改进这段代码? [英] How can I improve this code?

查看:88
本文介绍了我该如何改进这段代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在访问2003 db中的文本框后面有这个代码。问题

是10个不同的文本框我有10次。我只是觉得

应该有一个更好的方法来写这个并且只是打电话。


有人可以看看并告诉我。 />

谢谢,


************************** ************************ *****


Private Sub LBL_Renewal_Myfile1_Click()

错误GoTo ErrHandle_Err


DoCmd.DoMenuItem acFormBar,acRecordsMenu,acSaveRecord ,, acMenuVer70


Dim SubLink1 As String

Dim SubLink2 As String


Dim PolicyLink1 As String

Dim PolicyLink2 As String


Dim Submission_Combo As String

Dim Policy_Combo As String

''拼凑3个字符串

''SubmissionLink

SubLink1 =" http:// cvgdev20 / myFileDemo?tab = submission& submissionId ="

SubLink2 = [Forms]![Frm_Submissions]![Submission_ID]


Submission_Combo = SubLink1 + SubLink2


''P olicyLink

PolicyLink1 =" http://cvgdev20 / myFileDemo?tab = policy& policyNumber ="

PolicyLink2 = Nz([Forms]![Frm_Submissions]![ Text427],0)


''Policy_Combo = PolicyLink1 + PolicyLink2& Chr(34)

Policy_Combo = PolicyLink1 + PolicyLink2

如果Len([Forms]![Frm_Submissions]![Text427])1则

FollowHyperlink Policy_Combo

Else

FollowHyperlink Submission_Combo


结束如果

ErrHandle_Exit:

退出Sub


ErrHandle_Err:

MsgBox错误$

恢复ErrHandle_Exit


结束子

I have this code behind a text box in my access 2003 db. The problem
is that I have it 10 times for 10 different text boxes. I just think
there should be a better way to write this once and just call it.

Can someone take a look and let me know.

Thanks,

************************************************** *****

Private Sub LBL_Renewal_Myfile1_Click()
On Error GoTo ErrHandle_Err

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Dim SubLink1 As String
Dim SubLink2 As String

Dim PolicyLink1 As String
Dim PolicyLink2 As String

Dim Submission_Combo As String
Dim Policy_Combo As String
''Putting together the 3 Strings
''SubmissionLink
SubLink1 = "http://cvgdev20/myFileDemo?tab=submission&submissionId="
SubLink2 = [Forms]![Frm_Submissions]![Submission_ID]

Submission_Combo = SubLink1 + SubLink2

''PolicyLink
PolicyLink1 = "http://cvgdev20/myFileDemo?tab=policy&policyNumber="
PolicyLink2 = Nz([Forms]![Frm_Submissions]![Text427], 0)

''Policy_Combo = PolicyLink1 + PolicyLink2 & Chr(34)
Policy_Combo = PolicyLink1 + PolicyLink2
If Len([Forms]![Frm_Submissions]![Text427]) 1 Then
FollowHyperlink Policy_Combo
Else
FollowHyperlink Submission_Combo

End If
ErrHandle_Exit:
Exit Sub

ErrHandle_Err:
MsgBox Error$
Resume ErrHandle_Exit

End Sub

推荐答案



恢复ErrHandle_Exit


结束子


Resume ErrHandle_Exit

End Sub


也许我误解了这个问题,但看起来好像你需要删除代码并将其放入一个单独的sub(称为

例子)sub textboxcode。然后你的文本框的代码应该是

读取;


私有子LBL_Renewal_Myfile1_Click()

调用textboxcode

end sub。


您需要使用上面的代码从每个文本框中调用它,

但是您显示的实际长代码只需要在您调用的子文本框中出现一次



Maybe I have misunderstood this question however it looks as if you
should remove the code and put it in a seperate sub called (for
example) sub textboxcode. Then the code for your text boxes should
read;

Private Sub LBL_Renewal_Myfile1_Click()
call textboxcode
end sub.

You would need to have the code above to call it from each text box,
however the actual long code you have shown would only need to appear
once, in the sub textboxcode you call.


9月26日上午7:57, keri< keridow ... @ hotmail.comwrote:
On Sep 26, 7:57 am, keri <keridow...@hotmail.comwrote:

也许我误解了这个问题但看起来好像你要删除
代码并将其放在一个单独的sub(称为

示例)sub textboxcode中。然后你的文本框的代码应该是

读取;


私有子LBL_Renewal_Myfile1_Click()

调用textboxcode

end sub。


您需要使用上面的代码从每个文本框中调用它,

但是您显示的实际长代码只需要在您调用的子文本框中出现一次


Maybe I have misunderstood this question however it looks as if you
should remove the code and put it in a seperate sub called (for
example) sub textboxcode. Then the code for your text boxes should
read;

Private Sub LBL_Renewal_Myfile1_Click()
call textboxcode
end sub.

You would need to have the code above to call it from each text box,
however the actual long code you have shown would only need to appear
once, in the sub textboxcode you call.



**********************************


所以,如果我理解你在说什么....如果我有10个文本框,所有

有不同的名字,例如:textbox1,textbox2,我应该把它们全部放在一段代码中,然后只需点击

文本框就可以调用它?


如果是这样,那就是我的想法,但我不知道如何在代码中循环使用
,或者在代码中使用case语句。你能帮助我吗?b $ b帮助我吗?我只是想而不是在10个单独的文本框中使用10个这样的文本框,只需要一个包含所有10个文本框的

调用就会更有效率。 />

**********************************

So if I understand what you are saying....if I have 10 text boxes, all
with different names, ex: textbox1, textbox2, etc. I should put them
all in one piece of code and then just call it from the click on the
text box?

If so, that is what I was thinking, but I don''t know exactly how to
loop through the code, or use a case statement in the code. Could you
help me out with that? I just think instead of having 10 of these for
10 separate text boxes, it would be much more efficient to have one
call that encompasses all 10 text boxes.


这篇关于我该如何改进这段代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆