John,
Thanks very much for that - I had no idea that several fields could have one primary key.
Khalid,
No need to explain your primary keys to me now.
Regards,
Dave W
----- Original Message -----Sent: Saturday, October 24, 2015 4:23 PMSubject: Re: [MS_AccessPros] Re: Current record or row colour be highlightedDave-
Khalid has a compound Primary Key composed of four fields, and he depends on that to avoid duplicates across the four field values.Kahlid-If you are under the impression that an AutoNumber must be a Primary Key, that is not the case. You can keep your current Primary Key.
John Viescas, AuthorMicrosoft Access 2010 Inside OutMicrosoft Access 2007 Inside OutMicrosoft Access 2003 Inside OutBuilding Microsoft Access ApplicationsSQL Queries for Mere Mortals(Paris, France)
On Oct 24, 2015, at 5:21 PM, 'Dave Williams' davewillgmale@gmail.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:
Hi Khalid,Please explain what you mean by "PK with the combination of four fields". As I said before, each table can only have one PK field. Thats what "Primary" means. I don't see why checks depend on whether a field is a PK or not. You can index a field with no-duplicates without it having to be a PK.Actually, the added ID field does not have to be a PK, so you don't have to change your existing fields at all.Regards,Dave----- Original Message -----Sent: Saturday, October 24, 2015 1:11 AMSubject: Re: [MS_AccessPros] Re: Current record or row colour be highlightedHi Dave,Thanks for your reply and work done.As you are suggesting to:Add "ID" AutoNumber field as Primary Key to CollectionVoucher table.I am worried because i have already a PK with the combination of four fields, if i remove them my lot of checks would not be working and then i have to do a lot of work for them.Any how i am very much thankful to you for getting the solution which you tested and did worked.I will have to think over to your advise, but i am not implementing it right now.Waiting for your comments & suggestions about my concern.Regards,Khalid
---In MS_Access_Professionals@yahoogroups.com, <davewillgmale@...> wrote :
Khalid,I have managed to implement highlighting on my experimental form, based on Crystal's method. Your long module is just for assisting the user to fill in the form, and should not affect matters. I can't get my textboxes on the main form to work, but it doesn't matter.Here is what I did:Add "ID" AutoNumber field as Primary Key to CollectionVoucher table.On CollectionVoucherssubform add:IDs as a hidden unbound textbox.
ID1 as a hidden textbox with Control Source ID.A Textbox filling the subform record and behind all other controls.
Conditional Format: (option under "Format" on Menu bar)
Condition 1 Expression is ([IDs]=[ID]) Or (IsNull([IDs] And IsNull([ID])))
I used light yellow fill for highlighting.Enabled: No
Locked: Yes
Name: HighlightForm Event Procedure On Current:Private Sub Form_Current()
If IsNull(Me.ID1) Then
Me.IDs = Null
Else
Me.IDs = Me.ID1
End If
End SubThe highlighting appears on any record that is selected, even the blank one waiting for input.Before arriving at this solution, I got the same effect without using conditional formatting, based on an example quoted by Bill, in the Files section, in a folder called 1_Samples, filename cont_form_bkColor.zip, which highlights a row based on a control's value.Regards,Dave W----- Original Message -----Sent: Thursday, October 22, 2015 9:19 PMSubject: Re: [MS_AccessPros] Re: Current record or row colour be highlightedHi Dave,I also do use Access 2003.Record Source of Main form is:SELECT [Consignment Number].ConsignmentNo, [Consignment Number].ExportDocsFROM [Consignment Number]ORDER BY [Consignment Number].ConsignmentNo;I'm copying full module of Main Form "Collection Voucher"========================Option Compare DatabasePrivate Sub ConsignmentNo_NotInList(NewData As String, Response As Integer)MsgBox "PCTL could not recognize this entry." & vbCrLf & _"Please choose an item from the drop down list." _, vbExclamation, "PCTL Management - Guide"Response = acDataErrContinueEnd SubPrivate Sub Form_Open(Cancel As Integer)DoCmd.MaximizeEnd SubPrivate Sub CmdCloseFrmCollectionVr_Click()On Error GoTo Err_CmdCloseFrmCollectionVr_ClickDoCmd.CloseDoCmd.OpenForm "Data Entry Menu"DoCmd.RestoreExit_CmdCloseFrmCollectionVr_Click:Exit SubErr_CmdCloseFrmCollectionVr_Click:MsgBox Err.DescriptionResume Exit_CmdCloseFrmCollectionVr_ClickEnd SubPrivate Sub CmsUndoCollectionVr_Click()On Error GoTo Err_CmsUndoCollectionVr_ClickDoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70Exit_CmsUndoCollectionVr_Click:Exit SubErr_CmsUndoCollectionVr_Click:MsgBox Err.DescriptionResume Exit_CmsUndoCollectionVr_ClickEnd SubPrivate Sub CmdDelRcrdCollectionVr_Click()On Error GoTo Err_CmdDelRcrdCollectionVr_ClickDoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70Exit_CmdDelRcrdCollectionVr_Click:Exit SubErr_CmdDelRcrdCollectionVr_Click:MsgBox Err.DescriptionResume Exit_CmdDelRcrdCollectionVr_ClickEnd SubPrivate Sub SortOrder_NotInList(NewData As String, Response As Integer)MsgBox "This entry could not be found." & vbCrLf & _"Please select an item from the drop down list" _, vbExclamation, "PCTL Management - Guide"Response = acDataErrContinueEnd Sub=======================First Control on Main form combo box "ConsignmentNo"Control Source --> UnboundRow Source --> SELECT [Consignment Number].ConsignmentNo, [Consignment Number].ExportDocs FROM [Consignment Number] ORDER BY [Consignment Number].ConsignmentNo DESC;ExportDocs --> Date fieldSecond Control on Main form "cmbExportDocs"Control Source --> =ConsignmentNo.Column(1)Locked --> Yes=======================This is full module of CollectionVouchersubformOption Compare DatabaseOption ExplicitFunction RateWithNonBranded()'Amount = Rate * WeightOfCartonEnd FunctionFunction RateWithBranded()'Me.Rate = Rate + 0.5'Amount = Rate * WeightOfCartonEnd FunctionPrivate Sub Amount_GotFocus()If IsNull(Rate) ThenMsgBox "Oops you forget to enter Rate." & vbCrLf & _"Please enter Rate." _, vbExclamation, "PCTL - Missing Entry"Rate.SetFocusEnd IfMe.Amount.Value = WeightOfCarton * RateEnd SubPrivate Sub BrandName_AfterUpdate()If Me.NewRecord ThenBrandName.DefaultValue = Chr(34) & BrandName & Chr(34)End IfEnd SubPrivate Sub BrandName_GotFocus()If IsNull(CartonNo) ThenMsgBox "Oops you forget to enter Carton No." & vbCrLf & _"Please enter Carton No." _, vbExclamation, "PCTL - Missing Entry"CartonNo.SetFocusEnd IfEnd SubPrivate Sub BrandName_NotInList(NewData As String, Response As Integer)Dim intAnswer As IntegerDim strSQL As StringintAnswer = MsgBox("Brand Name " & Chr(34) & NewData & _Chr(34) & " is not currently listed." & vbCrLf & _"Would you like to add it to the list now?" _, vbQuestion + vbYesNo, "PCTL")If intAnswer = vbYes ThenstrSQL = "INSERT INTO [Branded Items] ([BrandName])" & _"VALUES ('" & NewData & "');"DoCmd.SetWarnings FalseDoCmd.RunSQL strSQLDoCmd.SetWarnings TrueMsgBox "The new Brand Name: " & Chr(34) & NewData & Chr(34) & " has been added to the list." _, vbInformation, "PCTL"Response = acDataErrAddedElseMsgBox "Please choose a Brand Name from the list." _, vbInformation, "PCTL Management - Guide"Response = acDataErrContinueEnd IfEnd SubPrivate Sub CartonSuffix_AfterUpdate()If Me.NewRecord ThenCartonSuffix.DefaultValue = Chr(34) & CartonSuffix & Chr(34)End IfEnd SubPrivate Sub CartonSuffix_GotFocus()If IsNull(CartonNo) ThenMsgBox "Oops you forget to enter Carton No." & vbCrLf & _"Please enter Carton No." _, vbExclamation, "PCTL - Missing Entry"CartonNo.SetFocusEnd IfEnd SubPrivate Sub cmbClient_AfterUpdate()If Not IsNull(Me.cmbClient) Then' Apply a filterMe.Filter = "ClientCIN = " & Me.cmbClientMe.FilterOn = TrueEnd IfEnd SubPrivate Sub cmbClient_NotInList(NewData As String, Response As Integer)MsgBox "PCTL could not recognize this entry." & vbCrLf & _"Please choose an item from the drop down list." _, vbExclamation, "PCTL Management - Guide"Response = acDataErrContinueEnd SubPrivate Sub cmbDestination_GotFocus()If IsNull(cmbClient) ThenMsgBox "Oops you forget to select any Client" & vbCrLf & _"Please enter Client CIN." _, vbExclamation, "PCTL - Missing Entry"cmbClient.SetFocusEnd IfEnd SubPrivate Sub cmbDestination_NotInList(NewData As String, Response As Integer)Dim intAnswer As IntegerDim strSQL As StringintAnswer = MsgBox("Destination: " & Chr(34) & NewData & _Chr(34) & " is not currently listed." & vbCrLf & _"Would you like to add it to the list now?" _, vbQuestion + vbYesNo, "PCTL")If intAnswer = vbYes ThenstrSQL = "INSERT INTO Destination ([Destination])" & _"VALUES ('" & NewData & "');"DoCmd.SetWarnings FalseDoCmd.RunSQL strSQLDoCmd.SetWarnings TrueMsgBox "The new Destination: " & Chr(34) & NewData & Chr(34) & " has been added to the list." _, vbInformation, "PCTL"Response = acDataErrAddedElseMsgBox "Please choose a Destination Name from the list." _, vbInformation, "PCTL"Response = acDataErrContinueEnd IfEnd SubPrivate Sub cmbSetRoute_GotFocus()If IsNull(cmbDestination) ThenMsgBox "What is the Destination of this cargo?" & vbCrLf & _"Please enter Destination." _, vbExclamation, "PCTL - Missing Entry"cmbDestination.SetFocusEnd IfEnd SubPrivate Sub cmbSetRoute_NotInList(NewData As String, Response As Integer)Dim intAnswer As IntegerDim strSQL As StringintAnswer = MsgBox("Route " & Chr(34) & NewData & _Chr(34) & " is not currently listed." & vbCrLf & _"Would you like to add it to the list now?" _, vbQuestion + vbYesNo, "PCTL")If intAnswer = vbYes ThenstrSQL = "INSERT INTO Route ([Route])" & _"VALUES ('" & NewData & "');"DoCmd.SetWarnings FalseDoCmd.RunSQL strSQLDoCmd.SetWarnings TrueMsgBox "The new Route " & Chr(34) & NewData & Chr(34) & " has been added to the list." _, vbInformation, "PCTL"Response = acDataErrAddedElseMsgBox "Please choose a Route from the list." _, vbInformation, "PCTL"Response = acDataErrContinueEnd IfEnd SubPrivate Sub cmbTripNo_AfterUpdate()DoCmd.GoToRecord , , acLastCartonNo.SetFocusEnd SubPrivate Sub cmbTripNo_NotInList(NewData As String, Response As Integer)MsgBox "PCTL could not recognize this entry." & vbCrLf & _"Please choose an item from the drop down list." _, vbExclamation, "PCTL Management - Guide"Response = acDataErrContinueEnd SubPrivate Sub Form_BeforeUpdate(Cancel As Integer)Dim stLinkCriteria As StringDim rsc As DAO.Recordset' Don't check if not on a new rowIf Not Me.NewRecord Then Exit SubstLinkCriteria = "[CartonSuffix]='" & [CartonSuffix] & "' and [CartonNo]=" & [CartonNo] & " and [ClientCIN]=" & [cmbClientCIN] & _" and [ConsignmentNo]='" & [ConsignmentNo] & "'"Debug.Print stLinkCriteria'Check CollectionVoucher table for duplicate CartonNoIf DCount("*", "CollectionVoucher", stLinkCriteria) > 0 Then'Message box warning of duplicationMsgBox "This Carton Number: " & [CartonNo] & "-" & CartonSuffix & " has already been allotted" & vbCrLf & _"in Consignment No.'" & [ConsignmentNo] & "'," & vbCrLf & _"vide Contract No.'" & [cmbDeliveryVr] & "' for Client CIN: " & [cmbClientCIN] & "." _, vbInformation, "PCTL - Duplicate Entry"'Undo duplicate entryMe.UndoCartonNo.SetFocus'Go to record of original CartonNoSet rsc = Me.RecordsetClonersc.FindFirst stLinkCriteriaMe.Bookmark = rsc.BookmarkSet rsc = NothingCartonNo.SetFocusEnd If'---------------------------------------------Me.ExportDocs.Value = Parent.cmbExportDocs'-------------------' If ClientCIN is empty,If IsNull(Me.ClientCIN) Then' Copy it from cmbClientCINMe.ClientCIN = cmbClientCINEnd If'-------------------' If ClientName is empty,If IsNull(Me.ClientName) Then' Copy it from cmbClientNameMe.ClientName = cmbClientNameEnd If'-------------------' If Destination is empty,If IsNull(Me.Destination) Then' Copy it from cmbDestinationMe.Destination = cmbDestinationEnd If'-------------------' If TripNo is empty,If IsNull(Me.TripNo) Then' Copy it from cmbTripNoMe.TripNo = cmbTripNoEnd If'-------------------' If is empty BrandName'If IsNull(BrandName) Then' RateWithNonBranded'End If'-------------------'If Not IsNull(BrandName) Then' RateWithBranded'End If'-------------------' If HSCode is empty,If IsNull(Me.HSCode) Then' Copy it from cmbHSCodeMe.HSCode = cmbHSCodeEnd If'-------------------' If UnitOfCarton is empty,If IsNull(Me.UnitOfCarton) Then' Copy it from UnitOfCartonMe.UnitOfCarton = cmbUnitOfCartonEnd If'-------------------' If UnitOfGrossWeight is empty,If IsNull(Me.UnitOfGrossWeight) Then'Copy it from cmbUnitOfGrossWeightMe.UnitOfGrossWeight = cmbUnitOfGrossWeightEnd If'-------------------' If UnitOfNetWeight is empty,If IsNull(Me.UnitOfNetWeight) Then'Copy it from cmbUnitOfGrossWeightMe.UnitOfNetWeight = cmbUnitOfNetWeightEnd If'-------------------' If UnitOfQty is empty,If IsNull(Me.UnitOfQty) Then' Copy it from cmbUnitOfQtyMe.UnitOfQty = cmbUnitOfQtyEnd If'-------------------' If UnitOfValue is empty,If IsNull(Me.UnitOfValue) Then' Copy it from cmbUnitOfQtyMe.UnitOfValue = cmbUnitOfValueEnd If'-------------------' If Route is empty,If IsNull(Me.Route) Then' Copy it from cmbSetRouteMe.Route = cmbSetRouteEnd If'-------------------' If DeliveryVr is empty,If IsNull(Me.DeliveryVr) Then' Copy it from cmbSetDeliveryVrMe.DeliveryVr = cmbDeliveryVrEnd If'-------------------' If DeliveryVrDate is empty,If IsNull(Me.DeliveryVrDate) Then' Copy it from cmbDvDateMe.DeliveryVrDate = cmbDvDateEnd If'-------------------' If ProductNameRussian is emptyIf IsNull(Me.ProductNameRussian) Then' Copy it from cmbProductNameRussianMe.ProductNameRussian = cmbProductNameRussianEnd If'-------------------End SubPrivate Sub Form_Current()Me.RecordID_current = IIf([NewRecord], 0, [CartonNo]) ' Added this using Crystal mail for highlighting rowEnd SubPrivate Sub NetWeight_GotFocus()If IsNull(WeightOfCarton) ThenMsgBox "Oops you forget to enter Weight Of Carton." & vbCrLf & _"Please enter Weight." _, vbExclamation, "PCTL - Missing Entry"WeightOfCarton.SetFocusEnd IfEnd SubPrivate Sub ProductNameEnglish_AfterUpdate()Me.ProductNameRussian = cboProductNameRussianIf Me.NewRecord ThenProductNameEnglish.DefaultValue = Chr(34) & ProductNameEnglish & Chr(34)cboProductNameRussian.DefaultValue = Chr(34) & cboProductNameRussian & Chr(34)End IfEnd SubPrivate Sub ProductNameEnglish_NotInList(NewData As String, Response As Integer)MsgBox "PCTL could not recognize this entry." & vbCrLf & _"Please choose an item from the drop down list." _, vbExclamation, "PCTL Management - Guide"Response = acDataErrContinueEnd SubPrivate Sub ProductQty_AfterUpdate()If Me.NewRecord ThenProductQty.DefaultValue = Chr(34) & ProductQty & Chr(34)End IfEnd SubPrivate Sub ProductQty_GotFocus()If IsNull(ProductNameEnglish) ThenMsgBox "Oops you forget to select Product Name." & vbCrLf & _"Please enter Product Name." _, vbExclamation, "PCTL - Missing Entry"ProductNameEnglish.SetFocusEnd IfEnd SubPrivate Sub Rate_GotFocus()If IsNull(WeightOfCarton) ThenMsgBox "Oops you forget to enter Weight Of Carton." & vbCrLf & _"Please enter Weight." _, vbExclamation, "PCTL - Missing Entry"WeightOfCarton.SetFocusEnd IfDim varRate As VariantvarRate = DLookup("DestinationRate", "tblDestinationRates", _"Destination = '" & Me.cmbDestination & _"' AND ProductNameEnglish = '" & Me.ProductNameEnglish & "'")Me.Rate = Nz(varRate, 0)End SubPrivate Sub WeightOfCarton_AfterUpdate()Me.NetWeight.Value = WeightOfCarton - 1.5End SubPrivate Sub WeightOfCarton_GotFocus()If IsNull(ProductQty) ThenMsgBox "Is this Carton empty?" & vbCrLf & _"Please enter Product Quantity." _, vbExclamation, "PCTL - Missing Entry"ProductQty.SetFocusEnd IfEnd Sub===========================Does above information gives you some help.Regards,Khalid
---In MS_Access_Professionals@yahoogroups.com, <davewillgmale@...> wrote :
Hi Khalid,I only have Access 2003, and it only allows one Primary Key per table. I used your new information to create a form and subform, and I can enter data into the subform (which immediately generates a new empty record). I cannot enter anything into your two text boxes on the main form which both display #Name?, and I get an error saying "Control can't be edited; it's bound to ...". Does your main form have a record source? I have not added any event procedures.I have not tried to add highlighting yet, but an indicator pointer appears in the record-selector of the record I have selected, but maybe you don't have record-selectors enabled.Regards,Dave----- Original Message -----Sent: Thursday, October 22, 2015 3:20 PMSubject: Re: [MS_AccessPros] Re: Current record or row colour be highlightedHi Dave,I am sorry there was a slight mistake in the following line in my reply:~~~~~~~~~~~Main form "Collection Voucher" has two fields===== >Consignment -> Unbound -> Row Source ->SELECT [Consignment Number].ConsignmentNo, [Consignment Number].ExportDocs FROM [Consignment Number] ORDER BY [Consignment Number].ConsignmentNo DESC;cmbExportDocs -> its Control Source -> =ConsignmentNo.Column(1)~~~~~~~~~~~~Read as:~~~~~~~~~~~Main form "Collection Voucher" has two fieldsConsignmentNo -> Unbound -> Row Source ->SELECT [Consignment Number].ConsignmentNo, [Consignment Number].ExportDocs FROM [Consignment Number] ORDER BY [Consignment Number].ConsignmentNo DESC;cmbExportDocs -> its Control Source -> =ConsignmentNo.Column(1)~~~~~~~~~~~Sorry for inconvenience.Regards,Khalid
---In MS_Access_Professionals@yahoogroups.com, <khalidtanweerburrah@...> wrote :
Hi Dave,In my table "CollectionVoucher" 4 fields are assigned as PKField 1 = ConsignmentNo its Row Source is:SELECT [Consignment Number].ConsignmentNo, [Consignment Number].ExportDocs FROM [Consignment Number];Field 2 = ClientCIN its Row Source is:SELECT Clients.ClientCIN, Clients.ClientName FROM Clients ORDER BY Clients.ClientCIN;Field 3 = CartonNoField 4 = CartonSuffixTable "Products" has PK -> ProductNameEnglish~~~~~~~~~~~Main form "Collection Voucher" has two fieldsConsignment -> Unbound -> Row Source ->SELECT [Consignment Number].ConsignmentNo, [Consignment Number].ExportDocs FROM [Consignment Number] ORDER BY [Consignment Number].ConsignmentNo DESC;cmbExportDocs -> its Control Source -> =ConsignmentNo.Column(1)~~~~~~~~~~~~There is Before Update event on sub form to check duplicate CartonNo for same Consignment and same Client, that is why4 fields were assigned in table CollectionVoucher (with the instructions and guidance of John)Private Sub Form_BeforeUpdate(Cancel As Integer)Dim stLinkCriteria As StringDim rsc As DAO.Recordset' Don't check if not on a new rowIf Not Me.NewRecord Then Exit SubstLinkCriteria = "[CartonSuffix]='" & [CartonSuffix] & "' and [CartonNo]=" & [CartonNo] & " and [ClientCIN]=" & [cmbClientCIN] & _" and [ConsignmentNo]='" & [ConsignmentNo] & "'"Debug.Print stLinkCriteria'Check CollectionVoucher table for duplicate CartonNoIf DCount("*", "CollectionVoucher", stLinkCriteria) > 0 Then'Message box warning of duplicationMsgBox "This Carton Number: " & [CartonNo] & "-" & CartonSuffix & " has already been allotted" & vbCrLf & _"in Consignment No.'" & [ConsignmentNo] & "'," & vbCrLf & _"vide Contract No.'" & [cmbDeliveryVr] & "' for Client CIN: " & [cmbClientCIN] & "." _, vbInformation, "PCTL - Duplicate Entry"'Undo duplicate entryMe.UndoCartonNo.SetFocus'Go to record of original CartonNoSet rsc = Me.RecordsetClonersc.FindFirst stLinkCriteriaMe.Bookmark = rsc.BookmarkSet rsc = NothingCartonNo.SetFocusEnd If'---------------------------------------------There are some checks more in this event before End Sub, like'---------------------------------------------Me.ExportDocs.Value = Parent.cmbExportDocs'-------------------' If ClientCIN is empty,If IsNull(Me.ClientCIN) Then' Copy it from cmbClientCINMe.ClientCIN = cmbClientCINEnd If'-------------------and so on...End Sub~~~~~~~~~~~I do data entry in sub form. I hope i have described your question to some extent.I want to highlight the new record while doing data entry in it (in the sub form).Regards,Khalid
---In MS_Access_Professionals@yahoogroups.com, <davewillgmale@...> wrote :
Khalid,As you have not said what your tables are, I tried to reconstruct them from your subform SQL. I see that CartonNo and CartonSuffix are fields only in table CollectionVoucher, so they can't both be Primary Keys as you claim, unless there is another table that includes one of these fields as a primary key. Perhaps the Products table has HSCode as a primary key?What is the SQL for your parent form "Collection Voucher"? Is this where you do your data entry, and you want to highlight this record in the subform?Regards,Dave W----- Original Message -----Sent: Tuesday, October 20, 2015 7:57 PMSubject: [MS_AccessPros] Re: Current record or row colour be highlightedHi Crystal,First of all sorry that i was unable to reply to you and John, as i do not have access to internet.Crystal,I tried with all your instructions but am unable to highlight the row on my sub form which is continuous form. The only thing which i assume is that i have 4 fields set as PKConsignmnetNoClientCINCartonNoCartonSuffixYou wrote:WHERERecordID is the name of your primary key fieldSo in my case what would be RecordID, i did tried different patterns but could not get the result.Please help me more. May be i have not got your point.Regards,Khalid
---In MS_Access_Professionals@yahoogroups.com, <strive4peace2008@...> wrote :
Hi Khalid,
the row can be highlighted using conditional formatting and a control to keep track of the primary key (PK), which is set on the form current event.
TO HIGHLIGHT THE CURRENT RECORD IN A CONTINUOUS FORM
put the following textbox control on your form (I usually put it in the footer since there is often more unused space)
name --> RecordID_current
visible --> no
make the following textbox control in the detail section of your form:
name --> HighlightBox
left --> 0
top --> 0
width --> width of detail section
height --> height of detail section, like 0.2
enabled --> false
locked --> true
tabstop --> false
send this control to the back so it is behind all the other controls in the section
in the design view of the form, select HighlightBox
since HighlightBox is behind everything, you may need to select it using the object drop-down (combo box in the Properties window at the top)
conditional formatting
condition 1 --> Expression Is
--> [RecordID] = [RecordID_current]
example to also highlight a new record:
[RecordID_current] = nz([RecordID],RecordID_current)
change fill/back color to LIGHT YELLOW or light gray
or whatever color you want for your highlight
If my detail section background is White, I like to use light yellow for a highlight
WHERE
RecordID is the name of your primary key field
then, in the form OnCurrent event, assign a value to the unbound RecordID_current
being unbound, it will have the same value on every record
'~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub Form_Current()
Me.RecordID_current = IIf([NewRecord], 0, [RecordID])
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~~~~~~~~~~~~~~~~~~~~
'needed since Access 2007
Private Sub Form_BeforeInsert(Cancel As Integer)
Me.RecordID_current = me.RecordID
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~
where [RecordID] is the controlname (or fieldname) corresponding to your primary key.
~~~
Me.NewRecord is true if the form is on a new record. Throwing this in means that a new record will also be highlighted ... otherwise, since 2007, it will not. I had to create the BeforeInsert event to make it work as well ... maybe this was a temporary bug and the extra steps are no longer necessary
I used to use
nz(RecordID,0)
but I changed to
IIf([NewRecord], 0, [RecordID])
since 2007
~~~
I also put a click event on the highlight box to SetFocus to another control -- because, even though it is not enabled, it will come to the front and cover everything up if it is clicked on!
... however, you want the Click event to ALSO open another form (first setFocus, then open the form)
since HighlightBox spans your entire detail section, you can put a click event on that control.
be sure to save the record (if it needs it) before setting focus somewhere else.
~~~~~~~~~
If you are using a datasheet, I believe you will need to set up conditional formatting for each control as you can't use a control that spans the whole line as you can in a continuous form
warm regards,
crystal
Have a suggestion to improve Access?
http://access.uservoice.com/
~ have an awesome day ~
On 10/9/2015 7:24 AM, John Viescas JohnV@... [MS_Access_Professionals] wrote:Khalid-Choose some field in CollectionVoucher that is Required but that does not have a default value. Write Conditional Formatting for all the controls based on the value of that field. If the field is empty (Null or blank), then change the background color. As soon as the user fills in the value, the row should change back to its normal color.
John Viescas, AuthorMicrosoft Access 2010 Inside OutMicrosoft Access 2007 Inside OutMicrosoft Access 2003 Inside OutBuilding Microsoft Access ApplicationsSQL Queries for Mere Mortals(Paris, France)
On Oct 9, 2015, at 12:48 PM, Khalid Tanweer khalidtanweerburrah@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:
Hi All,I have a form "Collection Voucher" on its sub form "CollectionVouchersubform" when i am doing data entry on a new record I need that current row should be highlighted or to a custom colour defined.Sub forms SQL is as under:SELECT CollectionVoucher.ConsignmentNo, [Consignment Number].ExportDocs, CollectionVoucher.Route, CollectionVoucher.ClientCIN, Clients.ClientName, CollectionVoucher.Destination, CollectionVoucher.DeliveryVr, CollectionVoucher.DeliveryVrDate, CollectionVoucher.CartonNo, CollectionVoucher.CartonSuffix, CollectionVoucher.TripNo, CollectionVoucher.UnitOfCarton, CollectionVoucher.ProductNameEnglish, Products.ProductNameRussian, Products.HSCode, CollectionVoucher.BrandName, CollectionVoucher.ProductQty, CollectionVoucher.UnitOfQty, CollectionVoucher.WeightOfCarton, CollectionVoucher.UnitOfGrossWeight, CollectionVoucher.[Net Weight], CollectionVoucher.UnitOfNetWeight, CollectionVoucher.UnitOfValue, CollectionVoucher.Rate, CollectionVoucher.AmountFROM Products INNER JOIN ([Consignment Number] INNER JOIN (Clients INNER JOIN CollectionVoucher ON Clients.ClientCIN = CollectionVoucher.ClientCIN) ON [Consignment Number].ConsignmentNo = CollectionVoucher.ConsignmentNo) ON Products.ProductNameEnglish = CollectionVoucher.ProductNameEnglish;Help required please.Regards,Khalid
__._,_.___
Posted by: "Dave Williams" <davewillgmale@gmail.com>
Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (22) |
.
__,_._,___
Tidak ada komentar:
Posting Komentar