473,503 Members | 3,739 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Function HELP!!

94 New Member
This is a function i have written to align a series of addresses for printing labels.
However, for some reason the post code (A8) is not being moved up with the other address lines.

I can't for the life of me work out why. I need somebody with fresh eyes HELP!!

Expand|Select|Wrap|Line Numbers
  1. Function AddressLabels(ADD1, ADD2, ADD3, ADD4, ADD5, TOWN, COUNTRY, PCODE) As String
  2.  
  3. On Error GoTo AddressLabels_err
  4.  
  5. Dim A1, A2, A3, A4, A5, A6, A7, A8 As String
  6. Dim i As Integer
  7.  
  8. A1 = ADD1
  9. A2 = ADD2
  10. A3 = ADD3
  11. A4 = ADD4
  12. A5 = ADD5
  13. A6 = TOWN
  14. A7 = COUNTRY
  15. A8 = PCODE
  16.  
  17. For i = 1 To 7
  18.  
  19. If IsNull(A2) Then
  20.     A2 = A3
  21.     A3 = Null
  22. Else
  23.     A2 = A2
  24.     A3 = A3
  25. End If
  26.  
  27. If IsNull(A3) Then
  28.     A3 = A4
  29.     A4 = Null
  30. Else
  31.     A3 = A3
  32.     A4 = A4
  33. End If
  34.  
  35. If IsNull(A4) Then
  36.     A4 = A5
  37.     A5 = Null
  38. Else
  39.     A4 = A4
  40.     A5 = A5
  41. End If
  42.  
  43. If IsNull(A5) Then
  44.     A5 = A6
  45.     A6 = Null
  46. Else
  47.     A5 = A5
  48.     A6 = A6
  49. End If
  50.  
  51. If IsNull(A6) Then
  52.     A6 = A7
  53.     A7 = ""
  54. Else
  55.     A6 = A6
  56.     A7 = A7
  57. End If
  58.  
  59. If IsNull(A7) Then
  60.     A7 = A8
  61.     A8 = ""
  62. Else
  63.     A7 = A7
  64.     A8 = A8
  65. End If
  66.  
  67. Next i
  68.  
  69. AddressLabels = A1 & Chr(13) & Chr(10) & A2 & Chr(13) & Chr(10) & A3 & Chr(13) & Chr(10) & A4 & Chr(13) & Chr(10) & A5 & Chr(13) & Chr(10) & A6 & Chr(13) & Chr(10) & A7 & Chr(13) & Chr(10) & A8
  70.  
  71. Exit Function
  72.  
  73. AddressLabels_err:
  74.     AddressLabels = ""
  75.     Exit Function
  76.  
  77. End Function
I am running the function on an access report in a text box which has the following code:

Expand|Select|Wrap|Line Numbers
  1. =addresslabels([a1],[a2],[a3],[a4],[a5],[a6],[a7],[a8])
(a1 - a8 are the address fields supplied from an access query)
Oct 11 '07 #1
3 1400
MikeTheBike
639 Recognized Expert Contributor
This is a function i have written to align a series of addresses for printing labels.
However, for some reason the post code (A8) is not being moved up with the other address lines.

I can't for the life of me work out why. I need somebody with fresh eyes HELP!!

Expand|Select|Wrap|Line Numbers
  1. Function AddressLabels(ADD1, ADD2, ADD3, ADD4, ADD5, TOWN, COUNTRY, PCODE) As String
  2.  
  3. On Error GoTo AddressLabels_err
  4.  
  5. Dim A1, A2, A3, A4, A5, A6, A7, A8 As String
  6. Dim i As Integer
  7.  
  8. A1 = ADD1
  9. A2 = ADD2
  10. A3 = ADD3
  11. A4 = ADD4
  12. A5 = ADD5
  13. A6 = TOWN
  14. A7 = COUNTRY
  15. A8 = PCODE
  16.  
  17. For i = 1 To 7
  18.  
  19. If IsNull(A2) Then
  20.     A2 = A3
  21.     A3 = Null
  22. Else
  23.     A2 = A2
  24.     A3 = A3
  25. End If
  26.  
  27. If IsNull(A3) Then
  28.     A3 = A4
  29.     A4 = Null
  30. Else
  31.     A3 = A3
  32.     A4 = A4
  33. End If
  34.  
  35. If IsNull(A4) Then
  36.     A4 = A5
  37.     A5 = Null
  38. Else
  39.     A4 = A4
  40.     A5 = A5
  41. End If
  42.  
  43. If IsNull(A5) Then
  44.     A5 = A6
  45.     A6 = Null
  46. Else
  47.     A5 = A5
  48.     A6 = A6
  49. End If
  50.  
  51. If IsNull(A6) Then
  52.     A6 = A7
  53.     A7 = ""
  54. Else
  55.     A6 = A6
  56.     A7 = A7
  57. End If
  58.  
  59. If IsNull(A7) Then
  60.     A7 = A8
  61.     A8 = ""
  62. Else
  63.     A7 = A7
  64.     A8 = A8
  65. End If
  66.  
  67. Next i
  68.  
  69. AddressLabels = A1 & Chr(13) & Chr(10) & A2 & Chr(13) & Chr(10) & A3 & Chr(13) & Chr(10) & A4 & Chr(13) & Chr(10) & A5 & Chr(13) & Chr(10) & A6 & Chr(13) & Chr(10) & A7 & Chr(13) & Chr(10) & A8
  70.  
  71. Exit Function
  72.  
  73. AddressLabels_err:
  74.     AddressLabels = ""
  75.     Exit Function
  76.  
  77. End Function
I am running the function on an access report in a text box which has the following code:

Expand|Select|Wrap|Line Numbers
  1. =addresslabels([a1],[a2],[a3],[a4],[a5],[a6],[a7],[a8])
(a1 - a8 are the address fields supplied from an access query)
Hi

Would this be better
Expand|Select|Wrap|Line Numbers
  1. Function AddressLabels(ADD1, ADD2, ADD3, ADD4, ADD5, TOWN, COUNTRY, PCODE) As String
  2.  
  3. On Error GoTo AddressLabels_err
  4.  
  5.     AddressLabels = ADD1
  6.  
  7.     If ADD2 & "" <> "" Then AddressLabels = AddressLabels & Chr(13) & Chr(10) & ADD2
  8.     If ADD3 & "" <> "" Then AddressLabels = AddressLabels & Chr(13) & Chr(10) & ADD3
  9.     If ADD4 & "" <> "" Then AddressLabels = AddressLabels & Chr(13) & Chr(10) & ADD4
  10.     If ADD5 & "" <> "" Then AddressLabels = AddressLabels & Chr(13) & Chr(10) & ADD5
  11.     If TOWN & "" <> "" Then AddressLabels = AddressLabels & Chr(13) & Chr(10) & TOWN
  12.     If COUNTRY & "" <> "" Then AddressLabels = AddressLabels & Chr(13) & Chr(10) & COUNTRY
  13.     If PCODE & "" <> "" Then AddressLabels = AddressLabels & Chr(13) & Chr(10) & PCODE
  14.  
  15. Exit Function
  16.  
  17. AddressLabels_err:
  18.     AddressLabels = ""
  19.     Exit Function
  20.  
  21. End Function
??

MTB
Oct 11 '07 #2
QVeen72
1,445 Recognized Expert Top Contributor
Hi,

Change last part of your code:

Expand|Select|Wrap|Line Numbers
  1. If IsNull(A6) Then
  2.     A6 = A7
  3.     A7 = Null
  4. Else
  5.     A6 = A6
  6.     A7 = A7
  7. End If
  8.  
  9. If IsNull(A7) Then
  10.     A7 = A8
  11.     A8 = Null
  12. Else
  13.     A7 = A7
  14.     A8 = A8
  15. End If
  16.  
You are checking for Null, but Assigning a Blank String..

REgards
Veena
Oct 11 '07 #3
Lewe22
94 New Member
Cheers QVeen72, knew it would be something easy!
Oct 11 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
2790
by: JP SIngh | last post by:
Hi All I am trying to write a recursive function to list the managers and his employees in a tree like sctructure Manager 1 Emp1 Emp1.1 Emp 1.2 Emp 2
3
1996
by: | last post by:
Hello All, this is my first post. OK - The goal is to display the following (note: substitute 1' ' for 2'*') by using 3 recursive functions. 0123454321001234543210 **012343210012343210**...
2
2868
by: | last post by:
OK: Purpose: Using user's input and 3 recursive functions, construct an hour glass figure. Main can only have user input, loops and function calls. Recursive function 1 takes input and displays...
1
1787
by: Robert | last post by:
Vb.Net Make dll that contain one function. Help Please. I would like to call a function from different applications. I think i have to make a dll. I have Visual Basic.net 2003 Standard...
2
972
by: Goldie | last post by:
Can some please look at this function and maybe help me with why it's not doing as it's told... :) It's basicall meant to check to see if that field returned from database actually has any data...
2
2159
by: TC | last post by:
IE only (V6). First, I know very little JS and our resident expert is short on time, so I come to you for help. I have a dynamic CGI script (written in Progress) that generates the following...
1
1503
by: Abersparky | last post by:
Can someone help me with the mail() function??? The below is just to get myself going but I can't seem to get it working... is there something else I should be doing? I checked phpinfo() and the...
5
2040
by: turtle | last post by:
Background: I have a table of fields each field representing a month (Jan, Feb, Mar...). These are not a date field but more of a bucket to hold labor actuals. Along with the months their is...
0
1416
by: kang jia | last post by:
hi currently i am doing this search function for car booking website. it can search through either car seats or CarModel. it seems it able to do search function, however i small problem occurs to...
0
7315
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...
1
6974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7445
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5559
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4665
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3147
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1492
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
369
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.