Search code examples
excelvbabloomberg

How do you return EQS screens for a particular date using the Bloomberg VBA API?


I would like, for a given Bloomberg EQS screen, to be able to return the screen results on a given date.

I have been playing around with the Bloomberg file EqsDataExample.xls for a while now, but I have been unable to return anything other than the screen for the current date.

The Bloomberg function used in an Excel sheet is:

=BEQS(screen_name,"Asof=" & asof_date,)

Below is the function from the example, that I have modified unsuccessfully. I presume I need to do something with the override functionality, but it's just not there yet.

Public Sub MakeRequest(sScreenName As String, sScreenType As String, sGroup As String)

    Dim req As Request
    Dim nRow As Long

    Set req = refdataservice.CreateRequest("BeqsRequest")
    req.Set "screenName", sScreenName
    req.Set "screenType", sScreenType
    'req.Set "Group", sGroup

    ' >> My addition, trying to get the asof date override
    Dim overrides As Element
    Set overrides = req.GetElement("overrides")        
    Dim override  As Element
    Set override = overrides.AppendElment()
    override.SetElement "fieldId", "ASOF="
    override.SetElement "value", "20101130"
    'MsgBox req.Print
    ' <<

    ' The following code is used to request data for a custom field that is setup
    ' using EQS <GO> on the Bloomberg Professional service. To use, uncomment these
    ' next 3 lines of code and comment out the previous 3 lines of code (above)
    ' Set req = refdataservice.CreateRequest("CustomEqsRequest")
    ' req.GetElement("fields").AppendValue "#NameOfCustomField"  ' Add name of custom field with # prefix
    ' req.Append "securities", "IBM US Equity" ' Add name of your security

    ' Add a correlation id
    Dim cid As blpapicomLib2.CorrelationId

    ' Send the request
    Set cid = session.SendRequest(req)

    curRow = 0

End Sub

Solution

  • The solution is to set the fieldId to "PiTDate" - I found this in the Bloomberg API documentation.

    Here is the code that works:

    Public Sub MakeRequest(sScreenName As String, sScreenType As String, sGroup As String)
    
        Dim req As Request
        Dim nRow As Long
    
        Set req = refdataservice.CreateRequest("BeqsRequest")
        req.Set "screenName", sScreenName
        req.Set "screenType", sScreenType
        'req.Set "Group", sGroup
    
        ' My Code >>
        Dim overrides As Element
        Set overrides = req.GetElement("overrides")
        Dim override  As Element
        Set override = overrides.AppendElment()
        override.SetElement "fieldId", "PiTDate"
        override.SetElement "value", "20141130"
        'MsgBox req.Print
        ' <<
    
        ' The following code is used to request data for a custom field that is setup
        ' using EQS <GO> on the Bloomberg Professional service. To use, uncomment these
        ' next 3 lines of code and comment out the previous 3 lines of code (above)
        ' Set req = refdataservice.CreateRequest("CustomEqsRequest")
        ' req.GetElement("fields").AppendValue "#NameOfCustomField"  ' Add name of custom field with # prefix
        ' req.Append "securities", "IBM US Equity" ' Add name of your security
    
        ' Add a correlation id
        Dim cid As blpapicomLib2.CorrelationId
    
        ' Send the request
        Set cid = session.SendRequest(req)
    
        curRow = 0
    
    End Sub