subform conditional formating

G

Guest

hi ,
I have two questions and hope someone can help with this.
1.when I select any record in the subform, I want the back color of that
line to be changed.
2.I have a button that when i click will open another form for the related
subform record. what i want is , when i close the second form , and the first
form got activated , the cursor should remain in the same record I was on
before opening the second form.( suppose i am in the record 5 of the Invoices
subfom , i clicked the button to open the form 2 "Patients" , when I closed
the patients form , the Invoices form will be activated , and I want the
cursor to remain in the 5 record of the invoices subform.

thanks
 
M

Marshall Barton

mhmaid said:
I have two questions and hope someone can help with this.
1.when I select any record in the subform, I want the back color of that
line to be changed.
2.I have a button that when i click will open another form for the related
subform record. what i want is , when i close the second form , and the first
form got activated , the cursor should remain in the same record I was on
before opening the second form.( suppose i am in the record 5 of the Invoices
subfom , i clicked the button to open the form 2 "Patients" , when I closed
the patients form , the Invoices form will be activated , and I want the
cursor to remain in the 5 record of the invoices subform.


1. Presumably the subform is in continuous view (question
is moot in single view and it can not be done in datasheet
view). First add an unbound text box named txtCurLine ib
the subform's header section. Then add code to the form's
Current event:
Me.txtCurLine = Me.<primary key field>

Next, create an unbound text box in the detail section with
the back color you want on all the other records and size it
to fill the entire section. Use Format menu - Send to Back
to put it behind all the other controls. Using Format menu -
Conditional Formatting, select the Expession Is option,
enter the expression:
ptxtCurLine] = [<primary key field>]
and select the highlight color in the BackColor property.

You will probably also want to set all(?) the other
control's BackStyle to Transparent.


2. The current record does not change just because you open
and close another form. You must have some code (Requery?)
that is causing the form to move to the first record.
Presuming you can locate it, modify the code to save the
primary key before the requery and find the record with the
saved pk value after the requery.
 
G

G. Vaught

Behind each textbox control in the design view of the form, create an event
procedure in the GotFocus and Lost Focus event. 65535 = yellow and 16777215
= white. when you enter the field it turns yellow, when you exit it goes
back to white.

The Me. indicates this field in this form.
CompanyName is the field name
..BackColor is self-explanatory

Private Sub CompanyName_GotFocus()
Me.CompanyName.BackColor = "65535"
End Sub

Private Sub CompanyName_LostFocus()
Me.CompanyName.BackColor = "16777215"
End Sub
 

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