Access

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to do some character checking. I have a TextBox that coulds have as
many as two characters in the box. I would like to look at each character. Is
there a way to do this in Access (Visual Basic)? Please help me or tell me
where to look.
 
There are several ways to do this. Without knowing what you are doing, I
can't give an exact answer, but if you want to look at individual characters
in a string, you can use the Mid function
=Mid(Me.SomeTextBox, 1, 1) will return the first chacter
=Mid(Me.SomeTextBox, 2, 1) will return the second chacter
etc
See VBA Help for more details.
 
Klatuu, thanks for your help. I was able to use the 'Mid" function get the
data, but now I would like to replace it with another character. I tried the
following:

Input -> jsx2 = Mid(bidsuffix, 2, 1)


Output-> Mid(bidsuffix, 2, 1) = "1"

The input was good, but the output crashed with this message 'Invalid
procedure call or argument'. Please suggest what ever is correct, or just
tell me whats wrong with my statement.

Thanks again for your help
 
You get that error if the string you are using is not as long as indicated by
the arguments in the Mid statement. That is, in this case
Mid(bidsuffix, 2, 1) = "1"
bidsuffix is not 2 characters long
 
Klatuu, I am not sure why, but I pulled the followig:

jsx1 = Mid(bidsuffix, 1, 1)
jsx2 = Mid(bidsuffix, 2, 1)

And the data for both fields were correct. I tried to do the following and I
would not work. What am I doing wrong?

Mid(bidsuffix, 2, 1) = "1" Why will this not work, or how do I make it
work
 
I sould have said that bidsuffix is defined in the table as text three (3)
characters long.
 
I sould have said that bidsuffix is defined in the table as text three (3)
characters long.

That definition only sets the *maximum* size of the field. If the user puts
only one character into the field, Mid([field], 2, 1) will still return
#Error!.

John W. Vinson [MVP]
 
You can use this to ensure the varialbe is always 3 characters to avoid any
errors because of length:
bidsuffix = bidsuffix & Space(3 - len(bidsuffix))
 
Back
Top