Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing a Field in a Table

Status
Not open for further replies.

DSTR3

Technical User
Jan 21, 2005
41
US
I'm trying reference a field in a Table. I think the problem is this...

!Active.Value

I'm not sure if this is the way to refernce the field.
The field is Active in the SecurityDetails Table.

If Active is -1 then Ctl is -1
If Active is 0 then Ctl is 0

Ctl is a CheckBox.

Thanks
DS



Dim dbs As DAO.Database
Dim rst As DAO.Recordset

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SELECT * FROM SecurityDetails WHERE SecurityDetails.SecurityID = " & Me.TxtID & "", dbOpenDynaset)

With rst
If .EOF = False And .BOF = False Then
Dim Ctl As Control
For Each Ctl In Me.Controls
If Ctl.Tag = "9" Then
If !Active.Value = -1 Then
Ctl = -1
ElseIf !Active.Value = 0 Then
Ctl = 0
End If
End If
Next Ctl
End If
End With
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
 
This seems to be working better, at least I have a MsgBox popping up as a test. I still can't get the Checkbox to be checked off though. I put the PrivID in the Tag Property of the control.
Thanks
DS

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim Ctl As Control

Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SELECT * FROM SecurityDetails WHERE SecurityDetails.SecurityID = " & Me.TxtID & "", dbOpenDynaset)

With rst
Do Until .EOF
If !Active.Value = -1 Then
MsgBox "Active"
For Each Ctl In Me.Controls
If Ctl.Tag = !PrivID.Value Then
MsgBox "Active PrivID"
'Ctl.Value = -1
Else:
End If
Next Ctl
ElseIf !Active.Value = 0 Then
MsgBox "Not Active"
For Each Ctl In Me.Controls
If Ctl.Tag = !PrivID.Value Then
MsgBox "Not Active PrivID"
Ctl.Value = 0
Else:
End If
Next Ctl
End If
.MoveNext
Loop
End With
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing

 
How are ya DSTR3 . . .

You've posted [blue]two different secenario's[/blue] here! [purple]Be more specific[/purple] about what you want to accomplish . . .

Calvin.gif
See Ya! . . . . . .
 
Look at the line of code where you're trying to check the checkbox (Ctl.Value = -1). You have that line commented out...that's why your checkbox is not being "checked.
 
The reason there are 2 is that I'm movingtowars a solution here. I've isolated the problem.

ctl.tag = !PrivID.Value

It seems that if I do ctl.Tag = 1 it works, but the minute I refernce a field in the table. It doesn't take. Can you not refernce a field in a table. You can't reference a varaible? I don't understand, any help appreciated.
Thanks
DS
 
Try changing your field reference to .Fields("PrivID")

I'm not if it will help at all, but it's worth a shot.
 
DSTR3 . . .

The [blue]Tag[/blue] property is a string data type . . . if your trying to ping against numeric . . . well . . .

Perhaps something like:
Code:
[blue]    If [purple][b]Val([/b][/purple]Ctl.Tag[purple][b])[/b][/purple] = !PrivID.Value Then[/blue]

Calvin.gif
See Ya! . . . . . .
 
The Val() Thing works!
Thanks Everyone!
DS

Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim Ctl As Control
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SELECT * FROM Test WHERE Test.TestID = " & Me.TxtID & "", dbOpenDynaset)

With rst
Do Until .EOF
If !Active.Value = -1 Then
MsgBox "Active"
For Each Ctl In Me.Controls
If Val(Ctl.Tag) = !PrivID.Value Then
MsgBox "Active PrivID"
Ctl.Value = -1
Else:
End If
Next Ctl
ElseIf !Active.Value = 0 Then
MsgBox "Not Active"
For Each Ctl In Me.Controls
If Val(Ctl.Tag) = !PrivID.Value Then
MsgBox "Not Active PrivID"
Ctl.Value = 0
Else:
End If
Next Ctl
End If
.MoveNext
Loop
End With
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top