Code not working - please help =)

G

Gary

I have a text box which contains address information and the company
reference number. Sometimes the address is 3 lines long, sometimes the
address is four lines long, which means either of the two following
examples can occur.

name of company
Add1
Add2
Add3
Company No.

or...
name of company
Add1
Add2
Add3
Add4
Company No.

What I need to do is put each address line in its own field, and put
the company number in its own field. My idea is to check to see if
vartext(4) (the fifth line from the text box) starts with the phrase
'Company No' , if it does then it is the company number line and the
company number should be extracted from this line and put in the
company number field. This implies that address data for this record is
3 lines long, and so I can assign vartext(1), (2), and (3) to their
respective address fields in my form.

If however vartext(4) is does not start with the phrase 'Company No.'
then it will be an address line and should be put into the 4th address
field. In this case the next line will be the company number, so I will
assign vartext(1), (2), (3) and (4) as address fields and vartext(5) as
the company number.

I have the following code to do this, but it's not working.. can some
clever person spot my mistake?


If Left$(varText(4), 10) = "Company No" Then
companynumber = varText(4) ' assign the fifth line to
the variable stringcompanynumber
companyinteger = Mid(companynumber, 13) ' assign the 'number' out
of stringcompanynumber to companynumber
Me.Company_Reg_No.Value = companyinteger ' insert
companynumber into 'company reg no' field.
Else
Me.address4.Value = varText(4)
companynumber = varText(5) ' assign the fifth line to the
variable stringcompanynumber
companyinteger = Mid(companynumber, 13) ' assign the 'number' out of
stringcompanynumber to companynumber
Me.Company_Reg_No.Value = companyinteger ' insert companynumber
into 'company reg no' field.
End If

companynumber = varText(5) ' assign the fifth line to the
variable stringcompanynumber
companyinteger = Mid(companynumber, 13) ' assign the 'number' out of
stringcompanynumber to companynumber
Me.Company_Reg_No.Value = companyinteger ' insert companynumber
into 'company reg no' field.

Thanks in advance,

Gary-
 
A

Albert D.Kallal

Are you trying to print this??

You do erilze that if you set the "can shirink" setting of a text box, then
it will "move up"..and not be printed.

In other words, the reprot writeer has settings to ignore blank text box and
move everything up. So, if this is for a reprot,
then you don't need any code at all.

It is possbile you need this for a display on the screen. However, why not
use a SINGLE text box then?


dim txtResult as string


txtResult = NewLineCat(txtResult,me.company.value)

txtResult = NewLineCat(txtResult,me.Add1.value)
txtResult = NewLineCat(txtResult,me.Add2.value)
txtResult = NewLineCat(txtResult,me.Add3.value)

etc....


' at this point we have a text string that is delimnted by a crarrage
reutrn/new lone chrabet.

If you put in into ta text box (that is sized to 4, or 5 lines deep), then
it will correclty show. each above value on a seperate line

me.MyTextBox = txtResult


Our new line cat function can be placed in a standar code module......

Here it is:

Public Function NewLineCat(strText As String, vData As Variant) As String

If IsNull(vData) = False Then

If strText <> "" Then
strText = strText & vbCrLf
End If

strText = strText & vData
End If

NewLineCat = strText

End Function

I have to admit that use of arrays in programming languages has been much
reduced with the use of strings, and also that of collection
objects....arrays are just not much useful anymore, and they tend to be a
VERY clumbsy data structure.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top