Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing a table field's property 2

Status
Not open for further replies.

KeyserSoze

Programmer
May 18, 2000
79
0
0
US
In a Microsoft Access (2000 format) database, I have a table that contains a field that currently has the following characteristics:

Data Type: Number
Field Properties: Field Size = Decimal, Precision = 2


Is there a way in VBA to change the precision from 2 to 9?

Thanks!
 
You can try this, or you can read some information about it here

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
Andy:

What if the table name/column name has spaces in it? How would the ALTER statement look in that scenario?

Thanks!
 
First, I would avoid spaces in table of field names. Just because Access allows you to do so, I would not do that. Some other data bases (like Oracle) does not allow that. I use underscore instead of a space (for example: First_Name)

Anyway, to use the name with the spaces, use [], like [First Name]

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
It didn't like it. I received a '3293' run-time error.

I am using the following references:
[ul]
[li]Microsoft Access 16.0 Object Library[/li]
[li]Microsoft Office 16.0 Access database engine Object Library[/li]
[li]Microsoft Visual Basic for Application Extensibility 5.3[/li]

[/ul]

Thanks!
 
Could you share your code where you use ALTER statement?

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
Here is the code:

Public Sub Change_Field_Precision()

Dim dbsApplications As Database
Dim strSQL As String

Set dbsApplications = CurrentDb

strSQL = "ALTER TABLE [Applications Now] ALTER COLUMN [ADM_APPL_NBR] DECIMAL(9)"
dbsApplications.Execute (strSQL)
dbsApplications.Close

End Sub


Thanks!
 
Use ADO instead (add reference) and modify your code:
Code:
[COLOR=#4E9A06]'dbsApplications.Execute strSQL[/color]
CurrentProject.Connection.Execute strSQL


combo
 
Complete code

Code:
Public Sub Change_Field_Precision()
    Dim adoConn As ADODB.Connection
    Set adoConn = CurrentProject.Connection
    Dim strSQL As String
    strSQL = "ALTER TABLE [Applications Now] ALTER COLUMN [ADM_APPL_NBR] DECIMAL(9)"
    adoConn.Execute strSQL
    Set adoConn = Nothing
End Sub

Duane
Hook'D on Access
MS Access MVP
 
Thanks, dhookom and combo. That did the trick. Adding the Microsoft ActiveX to my reference list solved the problem.

Thanks, everyone, for your help on this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top