Ask Your Question

How can I Update a Data Base column with Basic Macro?

asked 2021-04-26 01:17:05 +0200

eddie.velloso gravatar image

updated 2021-04-26 01:22:56 +0200

Ratslinger gravatar image


. .

AtribuiCategoria(oForm As Object)
Dim vResult As Long         '   Return value
Dim oResultAs As Object '
Dim oQuery As Object            '
Dim oStatement As Object
Dim xStatement As Object        '

    xStatement = CreateUnoService("")
    Context = CreateUnoService("")
    oResult = CreateUnoService("")
    oQuery = CreateUnoService("")

Dim sSql As String              '   SQL statement
Dim bDirect                 '   Alias of DirectSQL
Dim tbDespesasCC As String
Dim tbCategoria As String
Dim fldCategoria As String 
Dim fldIDCategoria As String

    tbDespesasCC = "Despesas Conta Corrente"
    tbCategoria = "Categoria"
    fldCategoria = "Categoria"
    fldIDCategoria = "ID Categoria" 

    '   Execute command

    sSQL = "UPDATE tbDespesasCC SET Categoria = fldIDCategoria.Categoria"
    VResult = ExecuteSQL(sSql)
REM     oStatement = con.prepareStatement(sSql)
REM Set oResult = _ExecuteSql(sSql, bDirect)
REM If IsNull(oResult) Then GoTo Finally

edit retag flag offensive close merge delete


Edited question for clarity. Please use Formatted Text icon on toolbar for this.

Ratslinger gravatar imageRatslinger ( 2021-04-26 01:19:54 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2021-04-26 01:37:24 +0200

Ratslinger gravatar image


Your question does not state where you are executing the macro from. oForm as an parameter and not seen as used anywhere. Don't know what database you are using so will guess it is HSQLDB embedded. This matters as for SQL.

SQL field and table names when mixed case need to be surrounded by quotes and in a string by double quotes. You do not ExecuteSQL(... but in this case executeUpdate(...

For an example of this, see this post -> How to create a macro for use in base form via a button?

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2021-04-26 01:17:05 +0200

Seen: 19 times

Last updated: Apr 26