Bruce,
Your code worked, with minor modifications (had to add a paren, subtract
one, piddly stuff that Access prompted me to do, then add the code to
write
the two variables into the table).
I have even set the properties for the two generated fields so they don't
have tab stops and are color-coded (the user knows that green fields are
filled in automatically so she can see them but the cursor doesn't go
there).
I could remove them from the form altogether, but I think it serves as a
double-check for her to be able to see them without having to bounce
through
them.
There's just one tiny (but very annoying) problem. When I open the form,
CourseCode in the first record is highlighted. When you click the "add
record" button, nothing happens. However, if you press Enter, then you can
click the "add record" button and everything works great.
I know there's bound to be some little something that I'm doing wrong, but
I
am working nearly blind here. What do I need to do to avoid that extra
confusing step? I want the user to be able to open the form and click the
"add record" button without having to press Enter.
BTW, your input is GREATLY appreciated! Your solution seems very elegant
to
me.
liz
Here's what I'm using:
--------------
Private Sub CourseCode_Exit(Cancel As Integer)
Dim strCodeLength As String
Dim strRubric As String
Dim strCourseNo As String
Dim intLetterPart As Integer
If Not IsNull(Len(Me.CourseCode)) Then
strCodeLength = Len(Me.CourseCode)
If (Val(Right(Me.CourseCode, 4))) = 0 Then
intLetterPart = Len(Me.CourseCode) - 3
strCourseNo = Right(Me.CourseCode, 3)
strRubric = Left(Me.CourseCode, intLetterPart)
Else
intLetterPart = Len(Me.CourseCode) - 4
strCourseNo = Right(Me.CourseCode, 4)
strRubric = Left(Me.CourseCode, intLetterPart)
End If
If (Not IsNull(strRubric)) Then Me![Rubric] = strRubric
If (Not IsNull(strCourseNo)) Then Me![CourseNo] = strCourseNo
End If
End Sub
------------
BruceM said:
I posted a reply in that other thread, but I'm afraid it's not much help.
I have seen (and inherited) rather a number of databases that look nice,
but
that are chaotic behind the scenes and clunky to use. Some people are
impressed by bells and whistles, and will accept that, for instance, you
need to enter the employee's name over and over. As long as the
interface
has nice colors and pictures they're impressed.
I will continue to experiment with my parsing system. It seems to be an
unusual approach, which means either that I'm innovative or that there's
something wrong with it. I hope it's the former.
"Dij" <dijatcox.net> wrote in message
Bruce,
Thanks once again.
The non-scrolling continuous form problem is described in the Access
forms
area under the title "SECOND POST--continuous form scroll problem". Fly
in
the ointment, but frustrating when entering courses for a new student
because
only the course record you are entering is visible.
I will try your code in a little while. As far as I know, there are no
courses with anything less than three digits. LSU courses all have
four,
but
students do sometimes transfer courses from schools that use three
digits.
Thanks also for explaining the underlying logic behind the code.
This is a database that is used to track our department's graduate
students
and their programs of study. It's not used that much and it's not that
big
so
I'm not too worried about it not being perfectly normalized. I haven't
done
any programming in a long time, either. I'm just trying to get this
simple
system worked out so that the person who is using it is doing the
minimum
typing possible. The person who set up the database didn't have a clue
and
I've spent a fair amount of time reworking it but I'm just about at a
point
where much more work isn't worth the time and effort. We're just about
to
"good enough"...
Liz
:
Sometimes it is necessary to store data rather than linking to it. We
have
a situation where a name needs to be stored as it was when the record
was
created. Things like that come up sometimes. If a course description
is
variable you could have two or more descriptions for the course in the
Course table. A Yes/No field could activate the course that is being
used
at the moment, so that the source query for a combo box or list box
could
exclude records in which the box is not checked, or something like
that.
Or
you could store the information. I would prefer the first choice if
possible, but reworking an existing database could be troublesome.
As for combining two separate fields in a list box (or combo box) you
can
combine the fields in the row source query:
FullNumber: [DeptCode] & [CourseCode]
That sort of thing is done often for combining name fields into a full
name.
I have poked around a bit, and I know there is code for parsing a
letter/number string, but the variable lengths of the letter and
number
strings makes it more difficult.
Here is one thing I have played around with a bit. If the number
portion
(on the right end of CourseCode) is either three or four digits, you
could
do something like this in VBA (untested):
Dim strCodeLength as String
Dim strDeptCode as String
Dim strCourseNo as String
Dim intLetterPart as Integer
strCodeLength = Len(Me.CourseCode)
If (Val(Right(Me.CourseCode), 4)) = 0 Then
intLetterPart = Len(Me.CourseCode) - 3
strCourseNo = Right(Me.CourseCode, 3)
strDeptCode = Left(Me.CourseCode), intLetterPart)
Else
intLetterPart = Len(Me.CourseCode) - 4
strCourseNo = Right(Me.CourseCode, 4)
strDeptCode = Left(Me.CourseCode, intLetterPart)
End If
The idea is that if the course code is HIST123, the rightmost 4
characters
are T123. By using Val, this evaluates to 0. In that case, the
length
of
the string minus 3 (in this case, 4) is used in the Left function;
otherwise
the length of the string minus 4 is used in the left function. This
works
only if the numeric portion of CourseCode is either 3 or 4. As I
said, I
haven't tested the code except in abbreviated fashion in an unbound
text
box, but I would like to do so when I have a little more time.
For the other part of your post, what is this about a non-scrolling
continuous form?