VBA Mod - Add a field to a form and populate it in VBA

Hello, and welcome. Our Video Tutorial today is going to show how to add a custom field to a form in Dynamics, and how to populate that field with VBA code

 

In order to demonstrate this we're going to modify the item inquiry form and add the shipping weight field to that form.

 

Adding a Native Field

 

Code that accompanies the article:

Dim cn As New ADODB.Connection
Dim rst As New ADODB.Recordset
  
Sub openConnection()
    Set cn = UserInfoGet.CreateADOConnection
    cn.DefaultDatabase = UserInfoGet.IntercompanyID
End Sub
  
  
Private Sub Window_AfterOpen()
    openConnection
End Sub
          
Private Sub ItemNumber_Changed()
    If cn.State = 0 Then
        openConnection
    End If
      
    'get an item
    Dim cmd As New ADODB.Command
    cmd.CommandText = "zDP_IV00101SS_1"
    cmd.ActiveConnection = cn
    cmd.CommandType = adCmdStoredProc
    cmd.Parameters.Append cmd.CreateParameter("@ITEMNMBR", adVarChar, adParamInput, 31, Me.ItemNumber)
    Set rst = cmd.Execute
      
    If Not rst.EOF Then
        Me.ShippingWeight = rst("itemshwt")
    End If
      
End Sub
  

RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences