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

Highlight and Delete a Record 1

Status
Not open for further replies.

mesafloyd

Technical User
Aug 19, 2006
31
US
Hi,
Im not a seasoned programmer (hardware guy) so please respond in simple terms if you can.
Using..MS Access 2003

Two part question:

I have a very simple form (frmUPDATES) that has the records in rows that displays some fields of the record.

#1 I would like to have the fields of that record highlighted when any of the fields are selected/edited (i.e. in focus).. I tried the conditional formating feature, but it only highlights the one field that is infocus at a time, not the entire record when any field of that record is infocus.

#2 Also, I would like to add a button that allows the user to delete that entire <highlighted/infocus> record..
simple huh?... not for an old timer like me ...

Thanks for any help..
Floyd
 
Have a look at RoyVidar's post in this thread702-958217.

You will then have a key field that you can use to delete the record.
 
Thanks Remou for looking at this.

Im not sure where to go here.
To me, it kicks around the problem but is not specific enought form my inexperience.

I have tried the conditional formatting, but it is for highlighting the individual fields not for all fields of the record when one field is infocus.
(Im probably missing something..) can you simplify it more for me.

On the delete of an infocus record, I understand a button needs to be generated for that,,, that is not a problem, what is the sub call for deleting an infocus record?

Again, sorry for my inexperience, your help is really appreciated.
Floyd
 
Have you created a textbox in the Form Header of the continuous form, as per RoyVidar's post? If so, all you need is a little code in the current event:

Code:
Private Sub Form_Current()
'Me.ID is a reference to a control containing the ID field
'which is unique for this recordset.
    Me.txtTest = Me.ID
End Sub

After that, in design view highlight the complete row and choose Conditional Formatting. Choose Expression Is and enter:

[tt][id]=[txtTest][/tt]

As you can see, the names match up with the controls and fields in the Current event.

To delete, you will require one line and a command button:

Code:
Private Sub cmdDelete_Click()
    DoCmd.RunCommand acCmdDeleteRecord
End Sub

Make sure you add error coding at some stage.
 
Hi again.
Im just not getting it...I have the Records fields in the 'Detail' section of the form, not the 'Header'.

Can we try another way, using conditional formating?

This form displays 5 fields per record of all the records in the table.
In each row, I have the fields in 5 text boxes... TB1, TB2... TB5

I just want all 5 text boxes highlighted whenever any one of the 5 are being edited(infocus). That would basically highlight the record.

To highlight that record is 'infocus' cant I write an expression for each box that says something like ...

...If [TB1] hasfocus or if [TB2] hasfocus or if [TB3] hasfocus or if [TB4] hasfocus or if[TB5] hasfocus ... then set the color??

Or maybe something like that. I just don't know code well enough to write expressions. Seems to me the conditional formatting should do it for me. Am I out of line here?

I'm sorry I am out of your league
thanks for your understanding.
Floyd
 
Unfortunately, Conditional Formatting is quite limited. Creating an unbound form in the Form Header of a continuous form is not difficult, it is, perhaps the easiest way to highlight the current record. Why do you dislike this method?

If you have a continuous form as a Datasheet, you can click on the arrow head in the border and the record will be highlighted. You can then right-click and select delete or click the delete button on the toolbar. However, you will only have a certain amount of control of the form.
 
Thanks Remou for looking at this.
I guess my problem is my limited programming ability, and my fundamental grasp of the theory...
You say continuous form, mine has a headder and I put the record rows in the detail.. I would think it is the same method.
Regarding the unbound form... I will try again...

BTW,
The suggestion on the delete button put me on track and I implemented this, seems to work fine for the delete.
---begin
Private Sub Command123_Click()
On Error GoTo ProcErr
ResponseMSG = MsgBox(Prompt:="You are permanently deleting this record, are you sure?", Buttons:=vbYesNo)
If ResponseMSG = vbYes Then
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
End If

ProcExit:
Exit Sub

ProcErr:
If Err = 2501 Then ' user cancelled
Resume Next
Else
MsgBox Err.Number & ": " & Err.DESCRIPTION
Resume ProcExit
End If
End Sub
---end---
Only having
DoCmd.RunCommand acCmdDeleteRecord
in the sub, was a bit cumbersome for the user... so I found the above...

Thanks again
Floyd
Thanks again
 
The idea behind RoyVidar's solution is to put a single, unbound control, that is, a TextBox, not unbound form, in the form header that can hold a reference to the current record that appears in the detail section. It in no way interferes with the current form set-up, it merely involves adding an additional, unbound control and a very little coding. I suggest you re-read RoyVidar's post in the link I provided and then re-read my posts .
 
How are ya mesafloyd . . .
mesafloyd said:
[blue]Im just not getting it . . .[/blue]
Maybe your not getting it, but do you know how to follow instructions? I see no reason for you not to be able to get thru this . . .

Do you know how to put an [blue]unbound textbox[/blue] in the header of the form?

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Hi Remou and TheAceMan1
Thanks for hanging in with the old hardware guy(me)
I think Ive done what you suggested...
It is not working
Now to show how much a rookie I am..

I have made the unbound textbox in the header, I named it '..txtTest..'
---dumb Question #1... that box is visible in my form-ugh..

I have entered this code
Code:
Private Sub Form_Current()
'Me.ID is a reference to a control containing the ID field
'which is unique for this recordset.
    Me.txtTest = Me.ID
End Sub

I have added this in each of the (field) text boxes i want highlighted...
Code:
[textID]=[textTest]

To test it... when I put the cursor in one of the fields
I get a
"Compile error"
"Method or data member not found"
and the 'ID' is highlighted in blue in this line
Me.txtTest = Me.ID

when I hit OK on the compile error
VB highlights this line in yellow
Private Sub Form_Current()

Floyd
 
mesafloyd . . .

It appears you misunderstood the explanation Remou provided in the code:
Code:
[green]'Me.ID is a reference to a control containing the ID field
'which is unique for this recordset.[/green]
It was meant for you to change:
Code:
[blue]   Me.txtTest = Me.ID
to:
   Me.txtTest = Me.[purple][b]YourPrimaryKeyName[/b][/purple][/blue]
That is replace [purple]YourPrimaryKeyName[/purple] with the actual name of your primarykey . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Thanks TheAceMan1
That was it.... being such a rookie, I have probelms keeping up the acronyms

To complete this , to keep the 'txtTest' box from appearing in my header, I selected 'visible' to OFF.. which does work

Thanks so much to you all for forcing me to thin.
....
now to clean up the mess I created. ;-)

Floyd
 
I knew you could do it! [thumbsup2]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top