All pastes #1647101 Raw Edit

Format SQL

public text v1 · immutable
#1647101 ·published 2009-10-28 22:20 UTC
rendered paste body
Private Sub cmdSql2Vba_Click()

    Dim strSql As String
    Dim strIndent As String
    Dim strNextLine As String
    
    strIndent = "     "
    strNextLine = vbCrLf
    
    If IsNull(Me.txtSql) Then
        Beep
    Else

    
    
        strSql = Me.txtSql
        strSql = Trim(strSql)
        strSql = Replace(strSql, "  ", " ")
        strSql = Replace(strSql, "select", "SELECT" & strNextLine & strIndent)
        strSql = Replace(strSql, "from", strNextLine & "FROM" & strNextLine & strIndent)
        strSql = Replace(strSql, "insert into", "INSERT INTO")
        strSql = Replace(strSql, "where", strNextLine & "WHERE" & strNextLine & strIndent)
        strSql = Replace(strSql, "order by", strNextLine & "ORDER BY" & strNextLine & strIndent)
        strSql = Replace(strSql, ",", "," & strNextLine & strIndent)
        strSql = Replace(strSql, "with OWNERACCESS OPTION", "")
        strSql = Trim(strSql)
        
        
    Me.txtTidy = strSql
    


    End If


End Sub