Getting Error from Code

  • Thread starter Thread starter Gary Hull
  • Start date Start date
G

Gary Hull

I copied this code from you site

Dim Pos As Integer
Dim Str As String

Str = LTrim(ctlTextbox.Text)
Pos = InStr(Str, " ")
If Pos > 0 Then
ctlTextbox.Text = Left(Str, Pos - 1)
End If

I gives me an error
Run-time error '2115'
The Macro or function set to the BeforeUpdate or Validation Rule property
for this field is preventing Microsoft Access from saving the data in the
field

What do I need to do
 
I copied this code from you site

Dim Pos As Integer
Dim Str As String

Str = LTrim(ctlTextbox.Text)
Pos = InStr(Str, " ")
If Pos > 0 Then
ctlTextbox.Text = Left(Str, Pos - 1)
End If

I gives me an error
Run-time error '2115'
The Macro or function set to the BeforeUpdate or Validation Rule
property for this field is preventing Microsoft Access from saving the
data in the field

What do I need to do

the above code is in the beforeUpdate, there is no other code in this
project right now
 
Hi Gary

I'm guessing you have this code in ctlTextbox_BeforeUpdate.

You should move it to ctlTextbox_AfterUpdate. You may not change the value
of a control in the BeforeUpdate event. This event should be used only for
validation.

It looks like you are trying to ignore everything that has been entered
after and including the first space. You might like to consider just
ignoring the space key if it is pressed:

Private Sub ctlTextbox_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeySpace Then KeyAscii = 0
End Sub
 
Would help if you passed the right number of arguments. Make friends
with the help file...

InStr(1,(e-mail address removed)
 
Back
Top