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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Controlling Button on only one record

Status
Not open for further replies.

puforee

Technical User
Oct 6, 2006
741
US
I have a Form shown in continous view that has a button that is NOT Enabled. Whne the record becomes current, I use VB to chaeck another object on that form and on that record. If the condition of that object is checked (check box), I use a Me statement to enable the button.

However....this enables the button on all records at once. I only want it to enable the button on the current record if the conditions are met.

Help please...I know this should be easy but.

Private Sub Form_Current()
If [Forms]![frm_MainAdminSetup]![LockCourse] = -1 Then
Me.ArchiveCrsBtn.Enabled = True
ElseIf Me.ArchiveCrsBtn.Enabled = True Then
Me.ArchiveCrsBtn.Enabled = False
End If

End Sub
 
It's not easy since every ArchiveCrsBtn on your form has the same property values. Changing one button, changes all buttons. You might be able to use some type of conditional formatting of a text box to behave like a command button.

Duane
Hook'D on Access
MS Access MVP
 
OK..Duane....why can I control other objects by record..like check boxes, text fields etc?

I will try your suggestion.

Thanks,
 
Are the other objects (check boxes, etc) BOUND?

Sometimes computer problems are like genealogy... The answer to one problem leads to two more!
 
Yes...is that the reason...bound objects can be worked in individual records and unbound objects can't?
 
That is correct.. each row has it's own fields. Unbound has no home.

Sometimes computer problems are like genealogy... The answer to one problem leads to two more!
 
There is a possible kludge that might work for you. Assuming you have a yes/no field named Active in your table. You could use an Toggle Button on your continuous form that is bound to the Active field. Let's start by setting all Active values to -1 so it looks like the toggle buttons are depressed. Assuming your primary key field name is PrimaryKey, you could use the On Current event of the form to set the Active field of the current record to 0 so it is popped up. At the same time you would need to set the previous record's Active to -1 so it is depressed. You would also need to have code that would prohibit running code from the update of the record that isn't current. I would also run code in the form open to set all of the Active fields to -1.

Code:
Option Compare Database
Dim lngPrimaryKey As Long

Private Sub Form_Current()
    If lngPrimaryKey <> 0 Then
        CurrentDb.Execute "UPDATE [YourTableName] SET Active = -1 WHERE PrimaryKey = " & lngPrimaryKey
        Me.Refresh
    End If
    Me.Active = 0
    lngPrimaryKey = Me.PrimaryKey
End Sub

Duane
Hook'D on Access
MS Access MVP
 
So...if I am hearing correctly. In my "Main Admin Setup" table. I have a field "LockCouorse". This is a check box field 0 or -1. On the form I show all the table information plus I have an Archive button.

So. Am I suposed to create another field in my TABLE labeled "Archive" so I can have a Bound Toggle button. the I could use your code above...changing the names to the real ones, to control the position of the Toggle.

Am I close?
 
puforee,
That is basically a possible solution. You could also check the value of the LockCourse field to determine if clicking the toggle button does anything.

Duane
Hook'D on Access
MS Access MVP
 
OK...I am working with this. First issue
I have a dual primary key. Model and Course fields. But I do have an auto number field.

What do you suggest?
 
Will do..thanks again...almost done. See new posting....Analyze Form Toggle.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top