I'm struggling with a way to show the RM00101.INACTIVE field for Child Customers on the National Accounts Maintenance form. I don't want to restrict the Child Customers that show. I just need the checkbox to show if the Child account is Active ( unchecked ) or Inactive ( checked ).
I added a checkbox field to the ChildScroll scrolling window but I can't come up with a vba script to populate the checkbox based on the Child Accounts returned.
Any help or sample code would be appreciated.
Thanks
DavidF.
*This post is locked for comments
My code didn't work for your environment because we have different custom local fields, I am glad your code is working after looking to my snippet. :-)
Thanks Almas,
I marked yours as the answer even though your code did not work in my environment. You did help me clean up the jumbled mess of code I was trying to make work.
I started clean and came up with a working modification.
So to summarize:
*** Start of VBA Code ***
Option Explicit
'Open the ADO connection
Dim cn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim cmd As New ADODB.Command
Private Sub Grid_AfterLineLostFocus()
'This code clears all variables used and closes the connections.
If rst.State = adStateOpen Then rst.Close
If cn.State = adStateOpen Then cn.Close
End Sub
Private Sub Grid_BeforeLinePopulate(RejectLine As Boolean)
'Opens the connection to the Customer Master and retrieves the Inactive field
'This code looks to see if there is already an open connection and if
'so a command object for read-only recordsets will be established
If rst.State = adStateOpen And cn.State = adStateOpen Then
cmd.ActiveConnection = cn
'This retrieves the Inactive field from Customer Master
cmd.CommandType = adCmdText
cmd.CommandText = "SELECT INACTIVE FROM RM00101 WHERE CUSTNMBR='" & CustomerNumber & "' "
'This updates the CustInactive field which is a Checkbox Field Added via
'Modifier to the NationalAccountsMaintDetail grid
Set rst = cmd.Execute
CustInactive = rst!Inactive
Else
'If a connection is not open, then the following will establish a link
'to the data, create the recordset and select the data.
Set cn = UserInfoGet.CreateADOConnection
cmd.ActiveConnection = cn
cmd.CommandType = adCmdText
'Updates the CustInactive field
cmd.CommandText = "SELECT INACTIVE FROM RM00101 WHERE CUSTNMBR='" & CustomerNumber & "' "
Set rst = cmd.Execute
CustInactive = rst!Inactive
End If
End Sub
*** End of VBA Code ***
Thanks so much for your help. This is now working exactly the way I want it to.
David
Come on .. !
It is absolutely an honor Ms. Almas Mahfooz ;)
Just trying to be like great Saadi. :)
Nice article ... as usual, always such a hard working person ;)
here http://evspakistan.wordpress.com/2014/08/05/adding-customer-inactive-checkbox-to-national-accounts-form/ find code snippet for your requirement. Don't need to mention you have to mark modified form to do the stuff.
almas
Davis,
That's what I tell you on first place, that if going for VBA then you should have expertise on it.
Dexterity is the best option if you know it.
btw you didn't mention any error you are getting, while running your code.
I am not sure whether you can achieve your requirement by using VBA. But, you can achieve the same by using Dexterity.
Hope this helps!!!
Tried it, still not getting any results. I just want the grid to show whether the Child account is Active (0) or Inactive (1).
did you try writing this validation in grid_AfterLinePopulate, which is equivalent to line fill event in dexterity.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156