Getting Error from Code

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
 
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

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

Graham Mandeno

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
 
P

pietlinden

Would help if you passed the right number of arguments. Make friends
with the help file...

InStr(1,(e-mail address removed)
 
J

J. Goddard

The starting position is optional in instr, as stated in the help file
(A2000)

J.
 

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

Similar Threads

Update Textbox Contents 2
Can't Set Focus after remoing text from field 3
Trim Function 2
validation rule error 4
CPearsons import text code 3
Type Mismatch (13) 2
query to textbox 1
Mixed Case 2

Top