PC Review


Reply
Thread Tools Rate Thread

change field property

 
 
peljo via AccessMonster.com
Guest
Posts: n/a
 
      30th Mar 2006
Can you help me with the code to change the property of a field in a table.My
field is called code and i want to change the property from text into number.
I have made the following code:

Public Function ChangeProperty()

Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim prp As DAO.Property
Dim dbs As DAO.Database
Set dbs = CurrentDb
Set tdf = dbs.TableDefs("Pricelist")
Set fld = tdf.Fields("code")
Set prp = fld.CreateProperty("Format", dbsingle)
fld.Properties.Append prp
dbs.Close
Set fld = Nothing
Set tdf = Nothing
Set dbs = Nothing

End Function

I get the following error :


Property value must be set before using this method.

--
Message posted via http://www.accessmonster.com
 
Reply With Quote
 
 
 
 
Douglas J Steele
Guest
Posts: n/a
 
      30th Mar 2006
Your code is trying to change the Format, not the Type. You cannot change
the Type of a field using DAO once it's been added to a table. You can add a
new field of the correct type, run an update query to transfer existing
values from the old field to the new field, delete the old field then rename
the new field.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"peljo via AccessMonster.com" <u19312@uwe> wrote in message
news:5e0b6471ec2a5@uwe...
> Can you help me with the code to change the property of a field in a

table.My
> field is called code and i want to change the property from text into

number.
> I have made the following code:
>
> Public Function ChangeProperty()
>
> Dim tdf As DAO.TableDef
> Dim fld As DAO.Field
> Dim prp As DAO.Property
> Dim dbs As DAO.Database
> Set dbs = CurrentDb
> Set tdf = dbs.TableDefs("Pricelist")
> Set fld = tdf.Fields("code")
> Set prp = fld.CreateProperty("Format", dbsingle)
> fld.Properties.Append prp
> dbs.Close
> Set fld = Nothing
> Set tdf = Nothing
> Set dbs = Nothing
>
> End Function
>
> I get the following error :
>
>
> Property value must be set before using this method.
>
> --
> Message posted via http://www.accessmonster.com



 
Reply With Quote
 
chris.nebinger@gmail.com
Guest
Posts: n/a
 
      30th Mar 2006
I just wrote the code for that for another post, so....



Sub FieldChange()
'This will fail if the field is a part of any index or
relationship.....
'Additional code is needed if that is a possibility
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Set dbs = CurrentDb
Set tdf = dbs.TableDefs("Contacts")
Set fld = tdf.CreateField("LastName1", dbLong)
tdf.Fields.Append fld
dbs.Execute "Update Contacts set lastname1 = clong(lastname)"
tdf.Fields.Delete "LastName"
tdf.Fields.Refresh
Set fld = tdf.CreateField("LastName", dbLong)
tdf.Fields.Append fld
dbs.Execute "Update Contacts set lastname = lastname1"
tdf.Fields.Delete "LastName1"
tdf.Fields.Refresh
End Sub


Chris Nebinger

 
Reply With Quote
 
peljo via AccessMonster.com
Guest
Posts: n/a
 
      31st Mar 2006
Thank you for your reply.I copied your suggestion but i get an error : cannot
find function clong.Could you help ?
Public Function FieldChange()
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Set dbs = CurrentDb
Set tdf = dbs.TableDefs("Pricelist")
Set fld = tdf.CreateField("code1", dbLong)
tdf.Fields.Append fld
dbs.Execute "Update PriceList set code1 = clong(code)"
tdf.Fields.Delete "code"
tdf.Fields.Refresh
Set fld = tdf.CreateField("code", dbLong)
tdf.Fields.Append fld
dbs.Execute "Update PriceList set code = code1"
tdf.Fields.Delete "code1"
tdf.Fields.Refresh
End Function







(E-Mail Removed) wrote:
>I just wrote the code for that for another post, so....
>
>Sub FieldChange()
>'This will fail if the field is a part of any index or
>relationship.....
>'Additional code is needed if that is a possibility
> Dim dbs As DAO.Database
> Dim tdf As DAO.TableDef
> Dim fld As DAO.Field
> Set dbs = CurrentDb
> Set tdf = dbs.TableDefs("Contacts")
> Set fld = tdf.CreateField("LastName1", dbLong)
> tdf.Fields.Append fld
> dbs.Execute "Update Contacts set lastname1 = clong(lastname)"
> tdf.Fields.Delete "LastName"
> tdf.Fields.Refresh
> Set fld = tdf.CreateField("LastName", dbLong)
> tdf.Fields.Append fld
> dbs.Execute "Update Contacts set lastname = lastname1"
> tdf.Fields.Delete "LastName1"
> tdf.Fields.Refresh
>End Sub
>
>Chris Nebinger


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...dules/200603/1
 
Reply With Quote
 
peljo via AccessMonster.com
Guest
Posts: n/a
 
      31st Mar 2006
I have deleted the cong ad it works just fine.Thank you very mcuh !


(E-Mail Removed) wrote:
>I just wrote the code for that for another post, so....
>
>Sub FieldChange()
>'This will fail if the field is a part of any index or
>relationship.....
>'Additional code is needed if that is a possibility
> Dim dbs As DAO.Database
> Dim tdf As DAO.TableDef
> Dim fld As DAO.Field
> Set dbs = CurrentDb
> Set tdf = dbs.TableDefs("Contacts")
> Set fld = tdf.CreateField("LastName1", dbLong)
> tdf.Fields.Append fld
> dbs.Execute "Update Contacts set lastname1 = clong(lastname)"
> tdf.Fields.Delete "LastName"
> tdf.Fields.Refresh
> Set fld = tdf.CreateField("LastName", dbLong)
> tdf.Fields.Append fld
> dbs.Execute "Update Contacts set lastname = lastname1"
> tdf.Fields.Delete "LastName1"
> tdf.Fields.Refresh
>End Sub
>
>Chris Nebinger


--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...dules/200603/1
 
Reply With Quote
 
Douglas J Steele
Guest
Posts: n/a
 
      31st Mar 2006
It should have been CLng, not CLong, but as you've found, it's not really
necessary.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"peljo via AccessMonster.com" <u19312@uwe> wrote in message
news:5e0dfcf028f70@uwe...
> I have deleted the cong ad it works just fine.Thank you very mcuh !
>
>
> (E-Mail Removed) wrote:
> >I just wrote the code for that for another post, so....
> >
> >Sub FieldChange()
> >'This will fail if the field is a part of any index or
> >relationship.....
> >'Additional code is needed if that is a possibility
> > Dim dbs As DAO.Database
> > Dim tdf As DAO.TableDef
> > Dim fld As DAO.Field
> > Set dbs = CurrentDb
> > Set tdf = dbs.TableDefs("Contacts")
> > Set fld = tdf.CreateField("LastName1", dbLong)
> > tdf.Fields.Append fld
> > dbs.Execute "Update Contacts set lastname1 = clong(lastname)"
> > tdf.Fields.Delete "LastName"
> > tdf.Fields.Refresh
> > Set fld = tdf.CreateField("LastName", dbLong)
> > tdf.Fields.Append fld
> > dbs.Execute "Update Contacts set lastname = lastname1"
> > tdf.Fields.Delete "LastName1"
> > tdf.Fields.Refresh
> >End Sub
> >
> >Chris Nebinger

>
> --
> Message posted via AccessMonster.com
> http://www.accessmonster.com/Uwe/For...dules/200603/1



 
Reply With Quote
 
chris.nebinger@gmail.com
Guest
Posts: n/a
 
      31st Mar 2006
That's what I get for typing "Air Code"...

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change Field Property DEI Microsoft Access VBA Modules 5 12th Aug 2009 10:28 PM
Re: using VBA to change property of a field strive4peace Microsoft Access Form Coding 2 4th Jul 2008 07:57 PM
Change Field Property using VBA =?Utf-8?B?UmFmaQ==?= Microsoft Access Database Table Design 1 6th Oct 2006 07:25 PM
Re: Change Field.required property in ADOX Brendan Reynolds Microsoft Access Database Table Design 3 21st Feb 2005 10:13 PM
Change field property in an existing table hlam Microsoft Access 1 24th Oct 2004 08:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:27 PM.