Propósito

✔ Programação GLOBAL® - Quaisquer soluções e/ou desenvolvimento de aplicações pessoais, ou da empresa, que não constem neste Blog devem ser tratados como consultoria freelance. Queiram contatar-nos: brazilsalesforceeffectiveness@gmail.com | ESTE BLOG NÃO SE RESPONSABILIZA POR QUAISQUER DANOS PROVENIENTES DO USO DOS CÓDIGOS AQUI POSTADOS EM APLICAÇÕES PESSOAIS OU DE TERCEIROS.

.: Vitrine

Carregando artigos...

Views

Mostrando postagens com marcador trim. Mostrar todas as postagens
Mostrando postagens com marcador trim. Mostrar todas as postagens

VBA Access - Limpe o conteúdo de todos os campos de todas as Tabelas na sua aplicação MS Access





O que é o fenômeno chamado BIG DATA?




Que tal fazer uma faxina em todas as tabelas da sua aplicação desenvolvida com o MS Access?

Sub TrimAllTextFieldsAllTables()

  Dim db As DAO.Database

  Dim tbls As DAO.TableDefs

  Dim tbl As DAO.TableDef

  Dim thisTable As DAO.TableDef

  Dim SQLString As String

  Dim flds As DAO.Fields

  Dim fld As DAO.Field

  Dim hasText As Boolean

  

  Set db = CurrentDb

  Set tbls = db.TableDefs

  

  ' loop through each appropriate table (i.e. no linked or system tables)

  For Each tbl In tbls

    hasText = False 'added

    If tbl.Attributes = 0 Then

      Set thisTable = tbl

      ' grab all fields

      Set flds = thisTable.Fields

  

      SQLString = "UPDATE [" & tbl.Name & "] SET "

  

      ' if field is text, create SQL string to trim it

      For Each fld In flds

        If fld.Type = dbText Then

          Let hasText = True 'added

          Let SQLString = SQLString & _

                 "[" & fld.Name & "] = Trim([" & fld.Name & "]),"

        End If

      Next fld

  

      Let SQLString = Left(SQLString, Len(SQLString) - 1) & ";"

      If hasText Then 'added

        Debug.Print SQLString


        ' execute update statement on table

        db.Execute SQLString, dbFailOnError

      End If 'added

    End If

  Next tbl

  

End Sub


Tags: VBA, Access, TRIM, DAO, SQL



VBA Access - Limpe todos os Espaços dos Campos Texto - Trim all text fields in a MS Access database



Recentemente tive a necessidade de aparar campos texto numa tabela em um dos bancos de dados que precisei fazer manutenção.

Ao efetuar o loop através de cada tabela no banco de dados, eliminei todos os espaços desnecessários dos campos de texto. Agora todas as consultas de comparação funcionarão.

Esta versão também funcionará quando houver campos que não forem texto.


Sub TrimAllTextFieldsAllTables()
  Dim db As DAO.Database
  Dim tbls As DAO.TableDefs

  Dim tbl As DAO.TableDef
  Dim thisTable As DAO.TableDef
  Dim SQLString As String
  Dim flds As DAO.Fields
  Dim fld As DAO.Field
  Dim hasText As Boolean
  
  Set db = CurrentDb
  Set tbls = db.TableDefs
  
  ' loop through each appropriate table (i.e. no linked or system tables)
  For Each tbl In tbls
    hasText = False 'added
    If tbl.Attributes = 0 Then
      Set thisTable = tbl
      ' grab all fields
      Set flds = thisTable.Fields
  
      SQLString = "UPDATE [" & tbl.Name & "] SET "
  
      ' if field is text, create SQL string to trim it
      For Each fld In flds
        If fld.Type = dbText Then
          hasText = True 'added
          SQLString = SQLString & _
                 "[" & fld.Name & "] = Trim([" & fld.Name & "]),"
        End If
      Next fld
  
      SQLString = Left(SQLString, Len(SQLString) - 1) & ";"
      If hasText Then 'added
        Debug.Print SQLString
        ' execute update statement on table
        db.Execute SQLString, dbFailOnError
      End If 'added
    End If
  Next tbl
  
End Sub


Tags: VBA, Access, field, text, campo, texto, trim, 


diHITT - Notícias