473,385 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How can I improve this code?

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

Sep 26 '07 #1
10 1361
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.

Sep 26 '07 #2
On Sep 26, 7:57 am, keri <keridow...@hotmail.comwrote:
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.
**********************************

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.

Sep 26 '07 #3

Sorry I was rushing and didn't read your code properly. I'm guessing
your code submits the value from the textbox to a form, ttherefore the
code needs to know which textbox has called the code - am I correct?

Sep 26 '07 #4
On Sep 26, 8:51 am, keri <keridow...@hotmail.comwrote:
Sorry I was rushing and didn't read your code properly. I'm guessing
your code submits the value from the textbox to a form, ttherefore the
code needs to know which textbox has called the code - am I correct?
That's correct. The text box goes to a link and submits the values of
policy number, submission id

Sep 26 '07 #5
On Sep 26, 8:56 am, dwo...@gaic.com wrote:
On Sep 26, 8:51 am, keri <keridow...@hotmail.comwrote:
Sorry I was rushing and didn't read your code properly. I'm guessing
your code submits the value from the textbox to a form, ttherefore the
code needs to know which textbox has called the code - am I correct?

That's correct. The text box goes to a link and submits the values of
policy number, submission id
************************
Goes thorugh this code and picks up a submission id number:

**************************************
'SubmissionLink
SubLink1 = "http://cvgdev20/myFileDemo?tab=submission&submissionId="
SubLink2 = [Forms]![Frm_Submissions]![Submission_ID]

'Puts the above submission id number into a url link inside of a text
box
************************************
Submission_Combo = SubLink1 + SubLink2

'If there is a policy number it takes the policy number and puts that
number into the link referenced in PolicyLink1 inside of a text box
where you can link to the url
******************************

'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

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

So basicly there are 10 text boxes that display a "url" link. It
really is just text but behind the scenes, when you click on the text
inside the text box it runs this code and opens IE to a web site
containing the policy/submission id info.
Sep 26 '07 #6
So each textbox runs identical code with the exception of using the
contents of the textbox that was clicked on.

You need to pass to the code (example names textboxcode) the name of
the text box that was clicked on (that called the textboxcode sub).
I'm not certain how to do this, I think you would be able to store the
calling textbox name in a public variable for use in the code. I'd
look at access help for this.

As a guess - you'd need to declare your public variable then in the
code activated by clicking on the textbox as below;

Private Sub LBL_Renewal_Myfile1_Click()
'insert a line here to pass the name of the textbox to the public
variable
call textboxcode
end sub

then in your textboxcode sub refer to the variable instead of the
textbox name directly.

Sep 26 '07 #7
On Sep 26, 9:24 am, keri <keridow...@hotmail.comwrote:
So each textbox runs identical code with the exception of using the
contents of the textbox that was clicked on.

You need to pass to the code (example names textboxcode) the name of
the text box that was clicked on (that called the textboxcode sub).
I'm not certain how to do this, I think you would be able to store the
calling textbox name in a public variable for use in the code. I'd
look at access help for this.

As a guess - you'd need to declare your public variable then in the
code activated by clicking on the textbox as below;

Private Sub LBL_Renewal_Myfile1_Click()
'insert a line here to pass the name of the textbox to the public
variable
call textboxcode
end sub

then in your textboxcode sub refer to the variable instead of the
textbox name directly.
************************

I'll try that. Thanks,

Sep 26 '07 #8
No, no, no, what you want is a function, not a sub, and you can pass
any values you want into to it when you call it.

Example:

Sub textbox_Click()

Call Do_This(PolicyLink1, SubLink1)

End Sub

Public Function Do_This(data1 as Long, data2 as String)

<< do something with the data >>

End Function

Sep 26 '07 #9
diane <di***********@verizon.netwrote in
news:11********************@57g2000hsv.googlegroup s.com:
No, no, no, what you want is a function, not a sub, and you can
pass any values you want into to it when you call it.

Example:

Sub textbox_Click()

Call Do_This(PolicyLink1, SubLink1)

End Sub

Public Function Do_This(data1 as Long, data2 as String)

<< do something with the data >>

End Function
You can pass parameters to a sub procedure, in exactly the same way
as to a function. You do not need to use a function for this, the
difference between the sub and the fiunction is that the function
returns a value.

If the sub or function is in the same module as the calling code,
then it can and should be declared private.

Example:

Sub textbox_Click()
Do_This PolicyLink1, SubLink1
End Sub

Private sub Do_This(data1 as Long, data2 as String)
<< do something with the data >>
End Function


--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Sep 26 '07 #10
keri <ke********@hotmail.comwrote in
news:11**********************@w3g2000hsg.googlegro ups.com:
So each textbox runs identical code with the exception of using
the contents of the textbox that was clicked on.

You need to pass to the code (example names textboxcode) the name
of the text box that was clicked on (that called the textboxcode
sub). I'm not certain how to do this, I think you would be able to
store the calling textbox name in a public variable for use in the
code. I'd look at access help for this.

As a guess - you'd need to declare your public variable then in
the code activated by clicking on the textbox as below;

Private Sub LBL_Renewal_Myfile1_Click()
'insert a line here to pass the name of the textbox to the public
variable
call textboxcode
end sub

then in your textboxcode sub refer to the variable instead of the
textbox name directly.
You do not need a public variable at all, just declare the parameter
as part of the declaration of the sub procedure.

Private Sub LBL_Renewal_Myfile1_Click()
call textboxcode LBL_Renewal_Myfile1
end sub

Private sub textboxcode(boxname as string, optional another variable
as string)
' do your thing
end sub

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Sep 26 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: pembed2003 | last post by:
Hi all, I asked this question in the C group but no one seems to be interested in answering it. :-( Basically, I wrote a search and replace function so I can do: char source = "abcd?1234?x";...
3
by: Anand | last post by:
Hi Iam keen interested to improve my skills in c programming. Now Iam familiar with all the syntax and concepts. My main idea is to know how entire c compiler behaves in all circumstances(i.e...
9
by: Peng Jian | last post by:
I have a function that is called very very often. Can I improve its efficiency by declaring its local variables to be static?
23
by: philipl | last post by:
hi, I have some code here which basically look for within a string, the occurance of any 3 consectative characters which are the same. so AAA bbb etc would be reported by this function. I later...
6
by: Jéjé | last post by:
Hi, hoew can I improve the compilation process of a sharepoint website? my server is: 2 * P3 Xeom 1ghz 4go ram 2 * 36gb (mirror for OS and website) 2 * 36 Raid 0 (stripping; for temp files...
7
by: dphizler | last post by:
This is the basic concept of my code: #include <iostream.h> #include <math.h> #include <stdlib.h> int main() { double Gtotal, L, size, distance, theRandom; double Gi; int xi, xf, yi, yf,...
16
by: weidongtom | last post by:
Hi, I have just finished reading some tutorials on C, I am wondering how I could improve my skill. Is there any advice? Is reading others' codes the best way? If so, what type of codes are...
11
by: Peted | last post by:
Im using c# 2005 express edition Ive pretty much finished an winforms application and i need to significantly improve the visual appeal of the interface. Im totaly stuck on this and cant seem...
2
by: sdanda | last post by:
Hi , Do you have any idea how to improve my java class performance while selecting and inserting data into DB using JDBC Connectivity ......... This has to work for more than 8,00,000...
5
by: Gilles Ganault | last post by:
Hello I'm no PHP expert, and I'm reading "Building scalable web sites". In the tips section, the author mentions using templates to speed things up. I was wondering how the template engines...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.