reference a field

johnlatona123

Innovator
Local time
Today, 07:09
Joined
Sep 20, 2011
Messages
85
hi!

how do i reference a field in VBA to compare values in an if statement, please help me with the []'s and ,'s and whatnot.

my statement should read like:

private sub after update
if {textbox on form} {is = to or matches text} {field on a query or table} then
checkbox = true
end if
end sub

thanks!

john.
 
Try this:

private sub after update
if me.textboxname.value = tablename.fieldname then
me.checkboxname.value= -1
end if
end sub
 
still getting an error:

run time error 424
object required

my code:
Private Sub username_AfterUpdate()
If Me.username.Value = user info.username Then
Check7 = -1
End If
End Sub
 
You can't just compare a field in a table or query from a form unless it is part of the form's record source. Also, you can't have spaces in the names or else you have to surround them with square brackets.
 
still the same error, new table created with no spaces, and that table is in the forms record source.

Private Sub username_AfterUpdate()
If Me.username.Value = userinfo.username Then
Me.Check7.Value = -1
End If
End Sub
 
1. You are using the same name as the field - not good.
2. If you have a control named username and it is a bound control then it would be duplication checking it with the other.
3. If the control named username is not bound then change its name to txtUsername and then you should be able to use:

If Me.txtUsername = Me!username Then
 
it did not like the addition of txt to username.

i am not opposed to remaning/changing things if you have a method that would make this work.

i have 4 fields in my table:
ID - autonumber
username - text
password - text
access level - number

i plan to have 2 text fields in my form:
username entry
password entry

numerous "hidden" checkboxes that become true if data validates against the table from the username entry and password entry text boxes or becomes false if data does not match the table.

1 button on the form that opens another form based on criteria of the previously evaluated items

can you help me write that?
 
What are the names of the text boxes on your form? So is the name of your text box "username entry"? If so, then that is what you reference like:

If Me.[username entry] = Me!username Then
 
Private Sub username_AfterUpdate()
If [me.usernameentry] = Me!username Then
Me.Check7.Value = -1
End If
End Sub


this is not erroring out, but it is also not checking the box
 
huzzah!

this works..

Private Sub usernameentry_AfterUpdate()
If Me.[usernameentry].Value = Me!username Then
Me.Check7.Value = -1
End If
End Sub


now, how to write the part that makes the checkbox unchecked if the statment is not true....
 
Try this:
Code:
Private Sub usernameentry_AfterUpdate()
If Me.[usernameentry].Value = Me!username Then
Me.Check7.Value = -1
Else Me.Check7.Value = 0
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom