9 charaters...no more no less

R

RogueIT

I have a form that I has one field and one button
I am using DoCmd.RunCommand acCmdPaste to paste a 9 digit number but I want
to make sure that all 9 numbers get pasted. I know how to keep it from going
over 9 but I don't know how to make sure that at least 9 numbers are in the
field...
Any help would be greatly appreciated.
thanks,
RogueIT
 
K

Ken Snell \(MVP\)

In the button's Click procedure, add a validation like this:

Private Sub CommandButtonName_Click()
If Len(Me.TextBoxName.Value & "") <> 9 Then
MsgBox "There are not 9 characters in the field!"
Me.TextBoxName.SetFocus
Else
' I assume there are other steps here, as this step by itself would
' seem to be incomplete
DoCmd.RunCommand acCmdPaste
End If
End Sub
 
R

RogueIT

well Ideally I want to paste the number in the clipboard and make sure it is
9 digits and then make sure there are no duplicates in the column. I am
checking for duplicates with table rules but the 9 digits I am trying to
attack like this (with your help. One question though, you have
"Me.TextBoxName.Value" what does the Value hold. And I don't know if this
makes any differance but it is the backend of Access 2003.

thanks again,
RogueIT

**************************************************
Private Sub NewRecordBtn_Click()
Dim strmsg As String
On Error GoTo Err_NewRecordBtn_Click

Me!Blank_Num.SetFocus
DoCmd.RunCommand acCmdPaste
DoCmd.RunCommand acCmdSaveRecord
If Len(Me!NewRecordBtn) <> 9 Then
strmsg = MsgBox("Invalid Number!", vbOKOnly)

Else
strmsg = MsgBox("Blank Number Accepted", vbOKOnly)
DoCmd.RunCommand acCmdSaveRecord

End If

Err_NewRecordBtn_Click:


Resume Exit_NewRecordBtn_Click


Exit_NewRecordBtn_Click:

End Sub
***************************************************
 
J

John Vinson

I have a form that I has one field and one button
I am using DoCmd.RunCommand acCmdPaste to paste a 9 digit number but I want
to make sure that all 9 numbers get pasted. I know how to keep it from going
over 9 but I don't know how to make sure that at least 9 numbers are in the
field...
Any help would be greatly appreciated.
thanks,
RogueIT

Use an Input Mask

000000000

and/or check the Len() of the field in your code after the paste
operation.

John W. Vinson[MVP]
 
K

Ken Snell \(MVP\)

You said that you have a "field" on the form -- in reality, this is a
control on the form, and I assumed that it is a textbox. The code syntax
Me.TextBoxName.Value
is a generic way to reference that textbox (replace TextBoxName with the
actual name of the textbox).

Value is a property of the control, and it holds what has been entered into
the control by the user.

Me is a reference to the form itself, and it means that you are referring to
the textbox with the identified name on the form that is running the VBA
code.
 
R

RogueIT

Cool. thanks for the information...and help

Ken Snell (MVP) said:
You said that you have a "field" on the form -- in reality, this is a
control on the form, and I assumed that it is a textbox. The code syntax
Me.TextBoxName.Value
is a generic way to reference that textbox (replace TextBoxName with the
actual name of the textbox).

Value is a property of the control, and it holds what has been entered into
the control by the user.

Me is a reference to the form itself, and it means that you are referring to
the textbox with the identified name on the form that is running the VBA
code.
 
R

RogueIT

I tried an input mask but it allows for incomplete fields. I need a 9 digit
number.
and I would love to know how to use len. I read the help but it was not much
help.
could someone post the code on using len to test the lenghth of a control,
please.

thanks for everyone's help.
RogueIT
 
R

RogueIT

I am getting a compile error on the Me.NewRecordBtn.Value when I run this
**************************************************
Private Sub NewRecordBtn_Click()
Dim strmsg As String
On Error GoTo Err_NewRecordBtn_Click

Me!Blank_Num.SetFocus
DoCmd.RunCommand acCmdPaste
DoCmd.RunCommand acCmdSaveRecord

If Len(Me.NewRecordBtn.Value & "") <> 9 Then
************************************************
Can anyone help?
thanks,
Rogue
 
J

John Vinson

I am getting a compile error on the Me.NewRecordBtn.Value when I run this
**************************************************
Private Sub NewRecordBtn_Click()
Dim strmsg As String
On Error GoTo Err_NewRecordBtn_Click

Me!Blank_Num.SetFocus
DoCmd.RunCommand acCmdPaste
DoCmd.RunCommand acCmdSaveRecord

If Len(Me.NewRecordBtn.Value & "") <> 9 Then
************************************************
Can anyone help?
thanks,
Rogue

Well, the *BUTTON* doesn't have a value or a length. The control
(textbox?) into which you are pasting does.

Try

Len(Me!Blank_Num & " ")

instead. You don't need the .Value property, it's the default.

John W. Vinson[MVP]
 
Top