Ask Your Question
0

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

Edited:

. .

AtribuiCategoria(oForm As Object)
Dim vResult As Long         '   Return value
Dim oResultAs As Object '   com.sun.star.sdbc.XResultSet
Dim oQuery As Object            '   com.sun.star.ucb.XContent
Dim oStatement As Object
Dim xStatement As Object        '   com.sun.star.sdbc.XStatement

    xStatement = CreateUnoService("com.sun.star.sdbc.XStatement")
    Context = CreateUnoService("com.sun.star.sdbc.DatabaseContext")
    oResult = CreateUnoService("com.sun.star.XResultSet")
    oQuery = CreateUnoService("com.sun.star.XContent")


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

END SUB
edit retag flag offensive close merge delete

Comments

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
0

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

Ratslinger gravatar image

Hello,

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

Stats

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

Seen: 19 times

Last updated: Apr 26