Control Box Rules

  • Thread starter Thread starter PL
  • Start date Start date
P

PL

Hi

For Acess 2003. In designing Forms:

1) How do I ensure only number is entered into a control box?

2) For a Bound Control, I wish to set the Default Value as 2, but in Form
View when entering a new record, the Default Value remains at 0. How do I
correct this?

Thank you
 
Hi PL,
1) if the text box is bound to a number field, access will show an error
when a non-number is entered - although it will allow some things that can
be converted to a number. If you want only integers between 0 and 9, there
are examples of functions that check this.
Here's an example.
On the BeforeUpdate event of the textbox, put -->
If Not IsNumeric = True Then
Cancel = True
End If


The code below goes in to a standard module-->

Public Function IsNumericCheck(ByVal strTestChar As String) As Boolean
On Error GoTo Err_Handler
pstrProc = "IsNumericCheck"

Dim intI As Integer 'loop counter
Dim lngLen As Integer 'string length
Dim intTestChar As Integer
Dim strMsg As String


Const conFirstDigit = 48
Const conLastDigit = 57

lngLen = Len(strTestChar)

For intI = 1 To lngLen
intTestChar = Asc(UCase(strTestChar))

If (intTestChar >= conFirstDigit And intTestChar <= conLastDigit)
Then
IsNumericCheck = True
Else
IsNumericCheck = False
strMsg = "Only numbers 0 to 9 are allowed. " _
& vbCrLf & vbCrLf _
& "Correct entry or press Esc to cancel."
MsgBox prompt:=strMsg, buttons:=vbInformation, TITLE:=pstrT

Exit Function
End If
Next intI

Exit_Handler:
Exit Function
Err_Handler:
MsgBox Err.Number & " " & Err.Description
Resume Exit_Handler
End Function

2)
You can set the default value using the control's property dialog, on the
data tab, look for default value and put 2 there.
Also open the table that the bound control has for its control source and
see if that field has a default value of 0 - access often puts a 0 for the
default value for a number field in Access 2003. Delete the default value
from the table and save the table.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
Back
Top