UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Correct Sintaxis To Format Fields Using Dao, Access 2013    
 
   
yuri.alonzo
post Aug 11 2019, 09:44 PM
Post#1



Posts: 8
Joined: 9-August 19



Hello everybody

I'm using this code, but is not working properly... it seems that the first "Set fld =" is wrong and is aborted the execution (I'm using a global variable)
Am not sure if the rest of the code is correctly formated.

Thanks for your support !
***********************************
Function changeFormatFields()

Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim prop As DAO.Property

Set db = CurrentDb
Set tdf = db.TableDefs("tmp_reporte_con_ajustes")

Set fld = tdf.Fields("global_viñeta") ' global_viñeta is a global variable
Set prop = fld.CreateProperty("Format", dbDouble, "Standard")
fld.Properties.Append prop

Set fld = tdf.Fields("global_viñeta")
Set prop = fld.CreateProperty("DecimalPlaces", dbByte, 2)
fld.Properties.Append prop

Application.RefreshDatabaseWindow

End Function
Go to the top of the page
 
June7
post Aug 12 2019, 12:20 AM
Post#2



Posts: 877
Joined: 25-January 16



VBA variables should not be within quote marks.

--------------------
Attachments Manager is below the edit post window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
DEBUG! DEBUG! DEBUG! http://www.cpearson.com/Excel/DebuggingVBA.aspx
Go to the top of the page
 
yuri.alonzo
post Aug 12 2019, 11:56 AM
Post#3



Posts: 8
Joined: 9-August 19



I tried some more and the problem is in the line using the global variable

I try with the name of the field, directly, and works!
Set fld = tdf.Fields("D_DELSUR_01")

but when I use the variable and error occur

global_viñeta= "D_DELSUR_01"
Set fld = tdf.Fields("global_viñeta")

Then the sintax I'm using is wrong

I walk-in the code, line by line, and the format change is working correctly but the use of the global variable no

Any hint?
This post has been edited by yuri.alonzo: Aug 12 2019, 12:23 PM
Go to the top of the page
 
DanielPineault
post Aug 12 2019, 12:08 PM
Post#4


UtterAccess VIP
Posts: 6,901
Joined: 30-June 11



If global_viñeta is a VBA variable, then
CODE
Set fld = tdf.Fields("global_viñeta") ' global_viñeta is a global variable

should be (without the surrounding quotations)
CODE
Set fld = tdf.Fields(global_viñeta) ' global_viñeta is a global variable

--------------------
Daniel Pineault (2010-2019 Microsoft MVP, UA VIP, EE Distinguished Expert 2018)
Professional Help: https://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: https://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 
yuri.alonzo
post Aug 12 2019, 12:26 PM
Post#5



Posts: 8
Joined: 9-August 19



Daniel

I tried that but is the same error

perhaps like in SQL, I use (" & global_viñeta & ") or (' " global_viñeta " ') but is the same.... error

Aditional thoughs?
Go to the top of the page
 
yuri.alonzo
post Aug 12 2019, 12:30 PM
Post#6



Posts: 8
Joined: 9-August 19



Daniel and June7

I don't know what is wrong with my PC but...

I tried again and this time the solution is the variable without quotes !

Thanks both for your support
Go to the top of the page
 
DanielPineault
post Aug 12 2019, 12:32 PM
Post#7


UtterAccess VIP
Posts: 6,901
Joined: 30-June 11



Glad you got it working. At the end of the day, that's all that matters!

--------------------
Daniel Pineault (2010-2019 Microsoft MVP, UA VIP, EE Distinguished Expert 2018)
Professional Help: https://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: https://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 
ADezii
post Aug 12 2019, 12:58 PM
Post#8



Posts: 2,679
Joined: 4-February 07
From: USA, Florida, Delray Beach


  1. There are several mistakes in your Code and I honestly cannot believe that it is working at all.
    1. A Global Variable cannot be enclosed with Quotation Marks.
    2. The Type Argument for creating the Format Property must be dbText.
    3. There is no need to set a double-reference to the fld Object Variable.
    4. Unlike 'Format', 'DecimalPlaces' is not a First-Use Property that can be created using the CreateProperty() Method. This Property already exists and can be modified directly.
    5. You should always clean-up any Object Variables that you use in your Code.
  2. Public Variable Declaration:
    CODE
    Public strMyField As String
  3. Code Definition:
    CODE
    Dim db As DAO.Database
    Dim tdf As DAO.TableDef
    Dim fld As DAO.Field
    Dim prop As DAO.Property

    strMyField = "Test_Field"

    Set db = CurrentDb
    Set tdf = db.TableDefs("tblDemo")

    Set fld = tdf.Fields(strMyField)
    Set prop = fld.CreateProperty("Format", dbText, "Standard")
               fld.Properties.Append prop
        
    tdf.Fields(strMyField).Properties("DecimalPlaces").Value = 2

    db.Close
    Set db = Nothing
    Set fld = Nothing
    Set prop = Nothing

    RefreshDatabaseWindow
  4. The Code has been tested and is fully operational.
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    19th October 2019 - 02:17 AM