Field properties

  • Thread starter Thread starter netalie
  • Start date Start date
N

netalie

Hi, it would be very helpful if you can assist me with
the following:

1. How can i limit the number of characters entered into
a text field in a form, according to a different value
at each record?

2. I have a form, records are presented as table. What is
the VBA code for selection of the current record? lets
say, if a press a button next to that specific record. by
default it always goes to the first one, i want it to
select the record which is next to the button.
 
(1) You can put code in a Control's OnChange event to check the number of
characters that have been typed into that Control. Even easier may be to
capture Keystrokes on the Keypress event. If you've hit the limit of
characters for the Control, set the KeyASCII argument to 0 before exiting.

Without clarification, I can't answer the "different value at each record"
part. From where are you getting these different values?

(2) In Access, the term "current Record" as applied to Forms _means_
"selected Record", so I don't know how to answer this. Two, but not the only
two ways, to make a particular record current:

A. Create an SQL statement that will return only
the Record of interest, and use that SQL
statement to replace the Form's Record Source.
Particularly good when using an Access client
to a server database, or a split, multiuser
Access database in which the table is indexed
on the Field used as Criteria.

B. If you have the form opened on a RecordSource
that contains all the Records from which to select
one, and you know the Field that uniquely identifies
the Record you want, code similar to the following
(air code) may do what you want:

Me.RecordsetClone.FindFirst "[SubYourFieldHere] = " &
Me![SubControlContainingUniqueIDHere]
If Me.RecordsetClone.NoMatch = False Then
Me.Bookmark = Me.RecordsetClone.Bookmark
End If

* that's for a UniqueID that is numeric (like an AutoNumber or Long Integer,
for example); if it is text use this for the FindFirst:

Me.RecordsetClone.FindFirst "[SubYourFieldHere] = """ &
Me![SubControlContainingUniqueIDHere] & """"

Good luck with your project.

Larry Linson
Microsoft Access MVP
 
Hi,

for the first issue: i have another field that holds
maximun characters alowed for the record. i read the
explanation, but i don't know how to assimilate it in the
file...is there a function that counts number of
characters or something like that?
-----Original Message-----
(1) You can put code in a Control's OnChange event to check the number of
characters that have been typed into that Control. Even easier may be to
capture Keystrokes on the Keypress event. If you've hit the limit of
characters for the Control, set the KeyASCII argument to 0 before exiting.

Without clarification, I can't answer the "different value at each record"
part. From where are you getting these different values?

(2) In Access, the term "current Record" as applied to Forms _means_
"selected Record", so I don't know how to answer this. Two, but not the only
two ways, to make a particular record current:

A. Create an SQL statement that will return only
the Record of interest, and use that SQL
statement to replace the Form's Record Source.
Particularly good when using an Access client
to a server database, or a split, multiuser
Access database in which the table is indexed
on the Field used as Criteria.

B. If you have the form opened on a RecordSource
that contains all the Records from which to select
one, and you know the Field that uniquely identifies
the Record you want, code similar to the following
(air code) may do what you want:

Me.RecordsetClone.FindFirst "[SubYourFieldHere] = " &
Me![SubControlContainingUniqueIDHere]
If Me.RecordsetClone.NoMatch = False Then
Me.Bookmark = Me.RecordsetClone.Bookmark
End If

* that's for a UniqueID that is numeric (like an AutoNumber or Long Integer,
for example); if it is text use this for the FindFirst:

Me.RecordsetClone.FindFirst "[SubYourFieldHere] = """ &
Me![SubControlContainingUniqueIDHere] & """"

Good luck with your project.

Larry Linson
Microsoft Access MVP


Hi, it would be very helpful if you can assist me with
the following:

1. How can i limit the number of characters entered into
a text field in a form, according to a different value
at each record?

2. I have a form, records are presented as table. What is
the VBA code for selection of the current record? lets
say, if a press a button next to that specific record. by
default it always goes to the first one, i want it to
select the record which is next to the button.


.
 
If you want to enter text into a Control (call it txtText) but only up to a
maximum specified in another field (call it MaxChars), then create a Control
on the form (call it txtMax) bound to the field MaxChars. To see what is
happening, you can also create an unbound Control (call it txtCount) and put
the following code in the Keypress event of Control txtText:

Private Sub txtText_KeyPress(KeyAscii As Integer)

If Len(Me!txtText.Text) + 1 > Me!txtMax Then
KeyAscii = 0
Else
Me!txtCount = Len(Me!txtText.Text) + 1
End If

End Sub

A KeyAscii value of 0 enters nothing, so you simply prevent the user from
entering any additional characters.

An alternative would be, in the BeforeUpdate event of txtText, to check the
length and if it exceeds the maximum, issue a MsgBox to warn the user that
it is too long, then set the Cancel argument equal to True before returning.

Larry Linson
Microsoft Access MVP


Netalie said:
Hi,

for the first issue: i have another field that holds
maximun characters alowed for the record. i read the
explanation, but i don't know how to assimilate it in the
file...is there a function that counts number of
characters or something like that?
-----Original Message-----
(1) You can put code in a Control's OnChange event to check the number of
characters that have been typed into that Control. Even easier may be to
capture Keystrokes on the Keypress event. If you've hit the limit of
characters for the Control, set the KeyASCII argument to 0 before exiting.

Without clarification, I can't answer the "different value at each record"
part. From where are you getting these different values?

(2) In Access, the term "current Record" as applied to Forms _means_
"selected Record", so I don't know how to answer this. Two, but not the only
two ways, to make a particular record current:

A. Create an SQL statement that will return only
the Record of interest, and use that SQL
statement to replace the Form's Record Source.
Particularly good when using an Access client
to a server database, or a split, multiuser
Access database in which the table is indexed
on the Field used as Criteria.

B. If you have the form opened on a RecordSource
that contains all the Records from which to select
one, and you know the Field that uniquely identifies
the Record you want, code similar to the following
(air code) may do what you want:

Me.RecordsetClone.FindFirst "[SubYourFieldHere] = " &
Me![SubControlContainingUniqueIDHere]
If Me.RecordsetClone.NoMatch = False Then
Me.Bookmark = Me.RecordsetClone.Bookmark
End If

* that's for a UniqueID that is numeric (like an AutoNumber or Long Integer,
for example); if it is text use this for the FindFirst:

Me.RecordsetClone.FindFirst "[SubYourFieldHere] = """ &
Me![SubControlContainingUniqueIDHere] & """"

Good luck with your project.

Larry Linson
Microsoft Access MVP


Hi, it would be very helpful if you can assist me with
the following:

1. How can i limit the number of characters entered into
a text field in a form, according to a different value
at each record?

2. I have a form, records are presented as table. What is
the VBA code for selection of the current record? lets
say, if a press a button next to that specific record. by
default it always goes to the first one, i want it to
select the record which is next to the button.


.
 
Back
Top