Convert VBA to VB .Net and C#


Here is an excellent article on Converting Code from VBA to Visual Basic .Net . The article talks about many of the pitfalls in converting. In general converting from VBA to VB .Net is very straight forward. This article is a must read for developers just starting to use VTSO . In another article, Ten code conversions for VBA, VB .Net and C# will help you convert between all three languages. Developing Microsoft Office Solutions using C# is a good starting point for C# developers creating Office Solutions.

Comments (2)

  1. marina says:

    Private Property Let CustomReport_Source(RHS As String)

    ‘ Create report based on specified data source.

    Dim txtNew As Access.TextBox

    Dim lblNew As Access.Label

    Dim rstSource As ADODB.Recordset

    Dim fldData As ADODB.Field

    Dim lngTop As Long

    Dim lngLeft As Long

    lngLeft = 0

    lngTop = 0

    ‘ Set report’s RecordSource property.

    Me.Report.RecordSource = RHS

    ‘ Open recordset on specified record source.

    Set rstSource = New ADODB.Recordset

    rstSource.Open "SELECT * FROM [" & RHS & "];", _

    CurrentProject.Connection, adOpenForwardOnly

    ‘ Create corresponding label and text box controls for each field.

    For Each fldData In rstSource.Fields

    ‘ Create new text box control and size to fit data.

    Set txtNew = CreateReportControl(Me.Report.Name, acTextBox, _

    acDetail, , fldData.Name, lngLeft + 1500, lngTop)

    txtNew.SizeToFit

    ‘ Create new label control and size to fit data.

    Set lblNew = CreateReportControl(Me.Report.Name, acLabel, acDetail, _

    txtNew.Name, fldData.Name, lngLeft, lngTop, 1400, txtNew.Height)

    lblNew.SizeToFit

    ‘ Increment top value for next control.

    lngTop = lngTop + txtNew.Height + 25

    Next

    CustomReport_Source_End:

    On Error Resume Next

    rstSource.Close

    Set rstSource = Nothing

    Exit Property

    End Property

  2. Toan says:

    SELECT IIf(VanBan.VBID=2,"Co","Khong") AS Expr1

    FROM TypeCV INNER JOIN VanBan ON TypeCV.TypeID = VanBan.TYPE;

Skip to main content