I have been at this for months! I am a beginer please help.

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

Guest

Hello:

I have been trying to create a form that gets data from the user and then
according to that data if the left four numbers in the field Keystartpull are
a certain number then the keystart2pull is a certain 2 digit abreviation.
Well I have been trying to get this to work but everytime I type the name of
a field it changes it case and my program does not work.
My small program is below.

Private Sub Keystartpull_BeforeUpdate(Cancel As Integer)
Dim kstart1Pull
If Left(Keystartpull, 4) = "0246" Then
kstart1Pull = "KI"
End If
Kstart2Pull = kstart1Pull

but as you can see the keystart1Pull is not written the way it is on the
table. The way it is supposed to be written is keystart1pull (all
lowercase), Kstart2Pull is suppsed to be kstart2pull (all lowercase) what is
going on? When I browse for the objects related to my form, I only see the
objects as spelled incorrectly, not like the way they are spelled out in my
form or my table.

Thanks
 
Not certain but it sounds like the LCase function is being applied to the
string somewhere in the application. LCase(StringValue) returns the string
in all lowercase letters.

TomU
 
but as you can see the keystart1Pull is not written the way it is on the

Actually, since I can't see your table, there is no way that I can tell if
written the way it is in the table. I'm not sure I quite understand what
your problem is. Variables (like kstart1pull) and/or field names are not
case sensitive. Could you describe your problem with a bit more detail?
 
Lynn:

The core of my problem is that the program that I wrote does not work. The
table has the fields all in lower case, but when I write the program in a
form, the names of the fields are changed in case. That is the only reason I
think that my program does not work.

The program is supposed to look at the contents of keystartpull and
depending on those contents will place the initials in keystart2pull. It
not writting the initials in keystart2pull like it is supposed to.

Can you please guide me as to where to go from here?
 
do you mean the field names are in lower case or the data contained is in
lower case?
if it's the former it won't matter.
please try to explain your problem as clearly as possible.
 
Yes, it is the field names. I guess that would not be a problem then. So if
it's not the fieldnames, then what else could make that program not work?
 
Is it just that you're describing your field as keystart2pull, while in your
code you have kstart2pull? (The important thing, by the way, is the name of
the control, not of the underlying field supplying the data. Thought the
control will, by default, have the same name as the field. And that's case
insensitive.)
 
but as you can see the keystart1Pull is not written the way it is on the

"keystart1Pull" is not referenced in the code you posted at all, as either a
variable or a form control. when your control and variable names are so
close, make sure you're typing them correctly, so we can figure out what
you're talking about. also, it's difficult to distinguish the variable(s)
from the control(s) in your code, because you're not referring to the form
object of the controls, as

Me!ControlName

next, unless you have a good reason for putting this code in the
Keystartpull control's BeforeUpdate event, suggest you move the code to the
AfterUpdate event. makes more sense to base an action on the value of a
control, *after* the value has been accepted in the control.

last, forget the upper/lower case issue. as Lynn says, and as Marshall said
in your thread on 11/30, variables and field names in VBA are not case
sensitive, so

keystartpull

is the same as

KeyStartPull

or any other variation of capitalization.

also, suggest you turn off NameAutoCorrect in your database (if it's not
already off), and then compact the database. to turn off NameAutoCorrect,
open the database to the database window. on the menu bar, click
Tools|Options|General Tab. remove the checkmark from Track name AutoCorrect
info. click Apply, then OK. compact the db. that may make a difference in
the capitalization, or not, but it's a good idea to do it - for a long list
of other reasons.

here's a code template for updating a form control, based on the value in
another control. try tweaking it with the correct control names, and see if
it will work for you.

Private Sub ControlName_AfterUpdate()

If Left(Me!ControlName, 4) = "0246" Then
Me!OtherControlName = "KI"
End If

End Sub

hth
 
The program is supposed to look at the contents of keystartpull and
depending on those contents will place the initials in keystart2pull. It
not writting the initials in keystart2pull like it is supposed to.

Kitty,
Looking at your code it is very confusing what you are trying to do. The
code you posted is:
Private Sub Keystartpull_BeforeUpdate(Cancel As Integer)
Dim kstart1Pull
If Left(Keystartpull, 4) = "0246" Then
kstart1Pull = "KI"
End If
Kstart2Pull = kstart1Pull

It appears that "kstart1Pull" and "Kstart2Pull" are variables, even though
you did not declare "Kstart2Pull." From what you said here, it sounds like
you are trying to get the value of "kstart1Pull" to populate a field in a
table. If that's the case, then you may want to change your code to
something like this.

Private Sub Keystartpull_AfterUpdate(Cancel As Integer)
Dim kstart1Pull As String
If Left(Me.Keystartpull, 4) = "0246" Then
kstart1Pull = "KI"
End If
Me.Keystart2Pull = kstart1Pull
End Sub

You will notice that, as Tina suggested, I changed the location of the code
to the AfterUpdate event, as this seems a more logical place. Also. I have
referenced 2 form fields -- "Keystartpull" and "Keystart2Pull" -- using the
Me reference, because I'm assuming that this is what you are after. Below is
a shorter way to accomplish the same thing.

Private Sub Keystartpull_AfterUpdate(Cancel As Integer)
If Left(Me.Keystartpull, 4) = "0246" Then
Me.Keystart2Pull = "KI"
End If
End Sub

Feel free to post back if you have any further questions.
 
Back
Top