27 November, 2007

Using VBA to Mark Inventory Batches to Post to GL

I think this is pretty much common knowledge but it is a simple change you can make with VBA to ensure your inventory adjustments post to the GL. Paste this code below behind the Inventory Batch Entry window to mark the checkbox to post to the GL by Default and then prompt the user before posting without posting to the GL. This demonstrates a couple of handy VBA techniques you can use to alter and control the behavior of GP (forgive the formatting).

Option Explicit
Dim Msg, Style, Title, Help, Ctxt, Response, MyString, Default

Private Sub Comment_AfterGotFocus()

'Mark the Post to GL Checkbox after Comment Got Focus if not already marked

If PosttoGeneralLedger = 0 Then
PosttoGeneralLedger = 1
Changed = False
End If

End Sub

Private Sub Origin_AfterUserChanged()

'Mark the Post to GL Checkbox after changing the origin if not already marked

If PosttoGeneralLedger = 0 Then

PosttoGeneralLedger = 1
Changed = False

End If

End Sub

Private Sub Post_BeforeUserChanged(KeepFocus As Boolean, CancelLogic As Boolean)

If BatchID.Empty = False Then

If InventoryBatchEntry.PosttoGeneralLedger.Value = 0 Then

Msg = "Do you want to post this batch without posting to GL?" ' Define message.
Style = vbYesNoCancel + vbCritical ' Define buttons.
Title = "Great Plains" ' Define title.
Help = "DEMO.HLP\" ' Define Help file.
Ctxt = 1000 ' Define topic
Response = MsgBox(Msg, Style, Title, Help, Ctxt)

If Response = vbNo Then

InventoryBatchEntry.PosttoGeneralLedger.Value = 1

Else

If Response = vbCancel Then

CancelLogic = True

End If
End If
End If
End If
End Sub

1 comment:

Desana said...

Keep up the good work.