Text box validation

  • Thread starter gsnidow via AccessMonster.com
  • Start date
G

gsnidow via AccessMonster.com

Greetings folks. I am trying to use two text boxes as a restriction to a
command button. Right now I have If Me.txtUser_ID.value = Me.txtCurrent_user.
value Then rest of code. It is not working, eventhough both boxes have the
same value for my test record. Is there another way to check if the values
of these boxes is equal. Both fields are text datatype.
 
G

Guest

They may appear to be the same, but one might have leading or trailing
spaces. Note, using the Value property is not necessary. It is the default
property of a control. Try

If Trim(Me.txtUser_ID) = Trim(Me.txtCurrent_user) Then
 
G

gsnidow via AccessMonster.com

Klatuu, thanks for the quick reply. That did not work. Does it have to do
with the fact that txtCurrent_user is being populated by ado recorset?
txtUser_id is a populated by a default stamp of system_user. I am using SQL
Server 2000 with ADO to populate the txtCurrent_user box as follows.
Basically, if the current user is not the user whose user id is associated
with the record I don't want any editing to be possible. Right now I am
simply trying to change what the button's caption is, based on the
relationship between the two boxes.

Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open

Dim cn As adodb.Connection
Dim rsLOGIN_ID As Recordset
Dim strSQL As String
strSQL = "SELECT SYSTEM_USER AS LOGIN_ID"

Set rsLOGIN_ID = New adodb.Recordset
Set cn = Application.CurrentProject.Connection
rsLOGIN_ID.Open strSQL, cn, adOpenForwardOnly, adLockOptimistic

Me.txtCurrent_User = (rsLOGIN_ID("LOGIN_ID"))
Me.txtCurrent_User.Requery

If Len("" & Me.txtUser_id) > 0 And Trim(Me.txtUser_id) = Trim(Me.
txtCurrent_User) Then
Me.cmdTakeOwnership.Caption = "Release Ownership"
Else
Me.cmdTakeOwnership.Caption = "Take Ownership"
End If

Me.txtUser = (rsLOGIN_ID("LOGIN_ID"))
Me.txtUser.Requery



Exit_Form_Open:
Exit Sub

Err_Form_Open:
MsgBox Err.Description
Resume Exit_Form_Open
End Sub
 
G

gsnidow via AccessMonster.com

Klatuu, I am not sure what happened, I was messing around with it so much,
but it works now. Thanks for the tip.

Greg
I don't know for sure, but it should not make a difference.
Klatuu, thanks for the quick reply. That did not work. Does it have to do
with the fact that txtCurrent_user is being populated by ado recorset?
[quoted text clipped - 50 lines]
 

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

Top