PC Review


Reply
Thread Tools Rate Thread

Change Text to Memo

 
 
Bob Howard
Guest
Posts: n/a
 
      13th Mar 2009
Hi,

How can I execute a command (presumably using DAO) to change the data type
of an existing table field (and which already contains data) from "Text" to
"Memo"?

Thanks in advance...

bob h


 
Reply With Quote
 
 
 
 
Daniel Pineault
Guest
Posts: n/a
 
      13th Mar 2009
Bob,

I put this together rapidly for you. It should do the trick. At the very
least it will show you the basic concept and you can take it from there.
Enjoy!

'---------------------------------------------------------------------------------------
' Procedure : SwitchFieldType
' Author : CARDA Consultants Inc.
' Website : http://www.cardaconsultants.com
' Purpose : Switch a given table field to Memo
' Copyright : The following may be altered and reused as you wish so long as
the
' copyright notice is left unchanged (including Author, Website
and
' Copyright). It may not be sold/resold or reposted on other
sites (links
' back to this site are allowed).
'
' Input Variables:
' ~~~~~~~~~~~~~~~~
' sTableName - Name of the Table which has the field to switch
' sFieldName - Name of the field to switch to Memo Type
'
' Usage:
' ~~~~~~~~~~~~~~~~
' SwitchFieldType("tbl_Contact","Notes")
'
' Revision History:
' Rev Date(yyyy/mm/dd) Description
'
**************************************************************************************
' 1 2009-Mar-13 Initial Releas
'---------------------------------------------------------------------------------------
Function SwitchFieldType(sTableName As String, sFieldName As String)
On Error GoTo Error_Handler
Dim sSQL As String

''Execute the query statement under DAO like this:
'DBEngine(0)(0).Execute sSQL, dbFailOnError
''or under ADO like this:
'CurrentProject.Connection.Execute sSQL


sSQL = "ALTER TABLE " & sTableName & " ALTER COLUMN " & sFieldName & "
MEMO;"
DoCmd.SetWarnings False
DBEngine(0)(0).Execute sSQL, dbFailOnError
DoCmd.SetWarnings True

If Err.Number = 0 Then Exit Function

Error_Handler:
MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf &
"Error Number: " & _
Err.Number & vbCrLf & "Error Source: SwitchFieldType" & vbCrLf & "Error
Description: " & _
Err.Description, vbCritical, "An Error has Occured!"
Exit Function
End Function
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



"Bob Howard" wrote:

> Hi,
>
> How can I execute a command (presumably using DAO) to change the data type
> of an existing table field (and which already contains data) from "Text" to
> "Memo"?
>
> Thanks in advance...
>
> bob h
>
>
>

 
Reply With Quote
 
Bob Howard
Guest
Posts: n/a
 
      13th Mar 2009
Thanks. I think I see what you're after, but I'm still confused on how this
code locates the specific DATABASE involved. Actually, I'm going to run
this code to modify the field type (to Memo) for a table located within a
ANOTHER Access database.

I have a front-end / back-end application, and I need to send a special
Access app to the users of the application that can simply run to modify
their existing back-end database to make this change. Thus, the table
involved is not within the Access database of the running program.

bob


"Daniel Pineault" <(E-Mail Removed)> wrote in
message news:A40D230A-3579-4D31-930C-(E-Mail Removed)...
> Bob,
>
> I put this together rapidly for you. It should do the trick. At the very
> least it will show you the basic concept and you can take it from there.
> Enjoy!
>
> '---------------------------------------------------------------------------------------
> ' Procedure : SwitchFieldType
> ' Author : CARDA Consultants Inc.
> ' Website : http://www.cardaconsultants.com
> ' Purpose : Switch a given table field to Memo
> ' Copyright : The following may be altered and reused as you wish so long
> as
> the
> ' copyright notice is left unchanged (including Author,
> Website
> and
> ' Copyright). It may not be sold/resold or reposted on other
> sites (links
> ' back to this site are allowed).
> '
> ' Input Variables:
> ' ~~~~~~~~~~~~~~~~
> ' sTableName - Name of the Table which has the field to switch
> ' sFieldName - Name of the field to switch to Memo Type
> '
> ' Usage:
> ' ~~~~~~~~~~~~~~~~
> ' SwitchFieldType("tbl_Contact","Notes")
> '
> ' Revision History:
> ' Rev Date(yyyy/mm/dd) Description
> '
> **************************************************************************************
> ' 1 2009-Mar-13 Initial Release
> '---------------------------------------------------------------------------------------
> Function SwitchFieldType(sTableName As String, sFieldName As String)
> On Error GoTo Error_Handler
> Dim sSQL As String
>
> ''Execute the query statement under DAO like this:
> 'DBEngine(0)(0).Execute sSQL, dbFailOnError
> ''or under ADO like this:
> 'CurrentProject.Connection.Execute sSQL
>
>
> sSQL = "ALTER TABLE " & sTableName & " ALTER COLUMN " & sFieldName & "
> MEMO;"
> DoCmd.SetWarnings False
> DBEngine(0)(0).Execute sSQL, dbFailOnError
> DoCmd.SetWarnings True
>
> If Err.Number = 0 Then Exit Function
>
> Error_Handler:
> MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf
> &
> "Error Number: " & _
> Err.Number & vbCrLf & "Error Source: SwitchFieldType" & vbCrLf & "Error
> Description: " & _
> Err.Description, vbCritical, "An Error has Occured!"
> Exit Function
> End Function
> --
> Hope this helps,
>
> Daniel Pineault
> http://www.cardaconsultants.com/
> For Access Tips and Examples: http://www.devhut.net
> Please rate this post using the vote buttons if it was helpful.
>
>
>
> "Bob Howard" wrote:
>
>> Hi,
>>
>> How can I execute a command (presumably using DAO) to change the data
>> type
>> of an existing table field (and which already contains data) from "Text"
>> to
>> "Memo"?
>>
>> Thanks in advance...
>>
>> bob h
>>
>>
>>



 
Reply With Quote
 
Daniel Pineault
Guest
Posts: n/a
 
      13th Mar 2009
You could have mentioned that originally. Not a big thing to modify. Try
this instead



'---------------------------------------------------------------------------------------
' Procedure : SwitchFieldType
' Author : CARDA Consultants Inc.
' Website : http://www.cardaconsultants.com
' Purpose : Switch a given table field to Memo
' Copyright : The following may be altered and reused as you wish so long as
the
' copyright notice is left unchanged (including Author, Website
and
' Copyright). It may not be sold/resold or reposted on other
sites (links
' back to this site are allowed).
'
' Input Variables:
' ~~~~~~~~~~~~~~~~
' sDb - Database Path & Name to execute command against
' sTableName - Name of the Table which has the field to switch
' sFieldName - Name of the field to switch to Memo Type
'
' Usage:
' ~~~~~~~~~~~~~~~~
' SwitchFieldType("D:\Contacts\Contacts.mdb","tbl_Contact","Notes")
'
' Revision History:
' Rev Date(yyyy/mm/dd) Description
'
**************************************************************************************
' 1 2009-Mar-13 Initial Releas
'---------------------------------------------------------------------------------------
Function SwitchFieldType(sDb As String, sTableName As String, sFieldName As
String)
On Error GoTo Error_Handler
Dim db As DAO.Database
Dim sSQL As String

''Execute the query statement under DAO like this:
'DBEngine(0)(0).Execute sSQL, dbFailOnError
''or under ADO like this:
'CurrentProject.Connection.Execute sSQL

Set db = DBEngine.Workspaces(0).OpenDatabase(sDb)

sSQL = "ALTER TABLE " & sTableName & " ALTER COLUMN " & sFieldName & "
MEMO;"

DoCmd.SetWarnings False
db.Execute sSQL, dbFailOnError
DoCmd.SetWarnings True

Set db = Nothing

If Err.Number = 0 Then Exit Function

Error_Handler:
MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf &
"Error Number: " & _
Err.Number & vbCrLf & "Error Source: SwitchFieldType" & vbCrLf & "Error
Description: " & _
Err.Description, vbCritical, "An Error has Occured!"
Exit Function
End Function
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



"Bob Howard" wrote:

> Thanks. I think I see what you're after, but I'm still confused on how this
> code locates the specific DATABASE involved. Actually, I'm going to run
> this code to modify the field type (to Memo) for a table located within a
> ANOTHER Access database.
>
> I have a front-end / back-end application, and I need to send a special
> Access app to the users of the application that can simply run to modify
> their existing back-end database to make this change. Thus, the table
> involved is not within the Access database of the running program.
>
> bob
>
>
> "Daniel Pineault" <(E-Mail Removed)> wrote in
> message news:A40D230A-3579-4D31-930C-(E-Mail Removed)...
> > Bob,
> >
> > I put this together rapidly for you. It should do the trick. At the very
> > least it will show you the basic concept and you can take it from there.
> > Enjoy!
> >
> > '---------------------------------------------------------------------------------------
> > ' Procedure : SwitchFieldType
> > ' Author : CARDA Consultants Inc.
> > ' Website : http://www.cardaconsultants.com
> > ' Purpose : Switch a given table field to Memo
> > ' Copyright : The following may be altered and reused as you wish so long
> > as
> > the
> > ' copyright notice is left unchanged (including Author,
> > Website
> > and
> > ' Copyright). It may not be sold/resold or reposted on other
> > sites (links
> > ' back to this site are allowed).
> > '
> > ' Input Variables:
> > ' ~~~~~~~~~~~~~~~~
> > ' sTableName - Name of the Table which has the field to switch
> > ' sFieldName - Name of the field to switch to Memo Type
> > '
> > ' Usage:
> > ' ~~~~~~~~~~~~~~~~
> > ' SwitchFieldType("tbl_Contact","Notes")
> > '
> > ' Revision History:
> > ' Rev Date(yyyy/mm/dd) Description
> > '
> > **************************************************************************************
> > ' 1 2009-Mar-13 Initial Release
> > '---------------------------------------------------------------------------------------
> > Function SwitchFieldType(sTableName As String, sFieldName As String)
> > On Error GoTo Error_Handler
> > Dim sSQL As String
> >
> > ''Execute the query statement under DAO like this:
> > 'DBEngine(0)(0).Execute sSQL, dbFailOnError
> > ''or under ADO like this:
> > 'CurrentProject.Connection.Execute sSQL
> >
> >
> > sSQL = "ALTER TABLE " & sTableName & " ALTER COLUMN " & sFieldName & "
> > MEMO;"
> > DoCmd.SetWarnings False
> > DBEngine(0)(0).Execute sSQL, dbFailOnError
> > DoCmd.SetWarnings True
> >
> > If Err.Number = 0 Then Exit Function
> >
> > Error_Handler:
> > MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf
> > &
> > "Error Number: " & _
> > Err.Number & vbCrLf & "Error Source: SwitchFieldType" & vbCrLf & "Error
> > Description: " & _
> > Err.Description, vbCritical, "An Error has Occured!"
> > Exit Function
> > End Function
> > --
> > Hope this helps,
> >
> > Daniel Pineault
> > http://www.cardaconsultants.com/
> > For Access Tips and Examples: http://www.devhut.net
> > Please rate this post using the vote buttons if it was helpful.
> >
> >
> >
> > "Bob Howard" wrote:
> >
> >> Hi,
> >>
> >> How can I execute a command (presumably using DAO) to change the data
> >> type
> >> of an existing table field (and which already contains data) from "Text"
> >> to
> >> "Memo"?
> >>
> >> Thanks in advance...
> >>
> >> bob h
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Bob Howard
Guest
Posts: n/a
 
      13th Mar 2009
Thanks so much ... I'll work on this later tody and post back.

Sorry I didn't initially mention that the database is elsewhere. I had
already created some code (before I posted), but it was failing with an
error. I wasn't using SQL to perform the function, but rather I was using
(what I'll simply call) "other" DAO coding. Like:

Dim daoDatabase as Dao.Database
Dim daoTableDef as Dao.TableDef
Dim daoField as Dao.Field

' the path is passed to this program as a command string
Set daoDatabase = OpenDatabase(Command)
Set daoTableDef = daoDatabase.TableDefs("table name")
Set daoField = daoTableDef("field name")
daoField.Type = dbMemo

The above fails with error 3219 at the set daoField line.

I copied some code from elsewhere, modified it (to the above) and was hoping
to make it work (somehow). I'm really a newbie at this type of programming.

bob

"Daniel Pineault" <(E-Mail Removed)> wrote in
message newsAD8E862-3789-4D7F-BECF-(E-Mail Removed)...
> You could have mentioned that originally. Not a big thing to modify. Try
> this instead
>
>
>
> '---------------------------------------------------------------------------------------
> ' Procedure : SwitchFieldType
> ' Author : CARDA Consultants Inc.
> ' Website : http://www.cardaconsultants.com
> ' Purpose : Switch a given table field to Memo
> ' Copyright : The following may be altered and reused as you wish so long
> as
> the
> ' copyright notice is left unchanged (including Author,
> Website
> and
> ' Copyright). It may not be sold/resold or reposted on other
> sites (links
> ' back to this site are allowed).
> '
> ' Input Variables:
> ' ~~~~~~~~~~~~~~~~
> ' sDb - Database Path & Name to execute command against
> ' sTableName - Name of the Table which has the field to switch
> ' sFieldName - Name of the field to switch to Memo Type
> '
> ' Usage:
> ' ~~~~~~~~~~~~~~~~
> ' SwitchFieldType("D:\Contacts\Contacts.mdb","tbl_Contact","Notes")
> '
> ' Revision History:
> ' Rev Date(yyyy/mm/dd) Description
> '
> **************************************************************************************
> ' 1 2009-Mar-13 Initial Release
> '---------------------------------------------------------------------------------------
> Function SwitchFieldType(sDb As String, sTableName As String, sFieldName
> As
> String)
> On Error GoTo Error_Handler
> Dim db As DAO.Database
> Dim sSQL As String
>
> ''Execute the query statement under DAO like this:
> 'DBEngine(0)(0).Execute sSQL, dbFailOnError
> ''or under ADO like this:
> 'CurrentProject.Connection.Execute sSQL
>
> Set db = DBEngine.Workspaces(0).OpenDatabase(sDb)
>
> sSQL = "ALTER TABLE " & sTableName & " ALTER COLUMN " & sFieldName & "
> MEMO;"
>
> DoCmd.SetWarnings False
> db.Execute sSQL, dbFailOnError
> DoCmd.SetWarnings True
>
> Set db = Nothing
>
> If Err.Number = 0 Then Exit Function
>
> Error_Handler:
> MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf
> &
> "Error Number: " & _
> Err.Number & vbCrLf & "Error Source: SwitchFieldType" & vbCrLf & "Error
> Description: " & _
> Err.Description, vbCritical, "An Error has Occured!"
> Exit Function
> End Function
> --
> Hope this helps,
>
> Daniel Pineault
> http://www.cardaconsultants.com/
> For Access Tips and Examples: http://www.devhut.net
> Please rate this post using the vote buttons if it was helpful.
>
>
>
> "Bob Howard" wrote:
>
>> Thanks. I think I see what you're after, but I'm still confused on how
>> this
>> code locates the specific DATABASE involved. Actually, I'm going to run
>> this code to modify the field type (to Memo) for a table located within a
>> ANOTHER Access database.
>>
>> I have a front-end / back-end application, and I need to send a special
>> Access app to the users of the application that can simply run to modify
>> their existing back-end database to make this change. Thus, the table
>> involved is not within the Access database of the running program.
>>
>> bob
>>
>>
>> "Daniel Pineault" <(E-Mail Removed)> wrote in
>> message news:A40D230A-3579-4D31-930C-(E-Mail Removed)...
>> > Bob,
>> >
>> > I put this together rapidly for you. It should do the trick. At the
>> > very
>> > least it will show you the basic concept and you can take it from
>> > there.
>> > Enjoy!
>> >
>> > '---------------------------------------------------------------------------------------
>> > ' Procedure : SwitchFieldType
>> > ' Author : CARDA Consultants Inc.
>> > ' Website : http://www.cardaconsultants.com
>> > ' Purpose : Switch a given table field to Memo
>> > ' Copyright : The following may be altered and reused as you wish so
>> > long
>> > as
>> > the
>> > ' copyright notice is left unchanged (including Author,
>> > Website
>> > and
>> > ' Copyright). It may not be sold/resold or reposted on
>> > other
>> > sites (links
>> > ' back to this site are allowed).
>> > '
>> > ' Input Variables:
>> > ' ~~~~~~~~~~~~~~~~
>> > ' sTableName - Name of the Table which has the field to switch
>> > ' sFieldName - Name of the field to switch to Memo Type
>> > '
>> > ' Usage:
>> > ' ~~~~~~~~~~~~~~~~
>> > ' SwitchFieldType("tbl_Contact","Notes")
>> > '
>> > ' Revision History:
>> > ' Rev Date(yyyy/mm/dd) Description
>> > '
>> > **************************************************************************************
>> > ' 1 2009-Mar-13 Initial Release
>> > '---------------------------------------------------------------------------------------
>> > Function SwitchFieldType(sTableName As String, sFieldName As String)
>> > On Error GoTo Error_Handler
>> > Dim sSQL As String
>> >
>> > ''Execute the query statement under DAO like this:
>> > 'DBEngine(0)(0).Execute sSQL, dbFailOnError
>> > ''or under ADO like this:
>> > 'CurrentProject.Connection.Execute sSQL
>> >
>> >
>> > sSQL = "ALTER TABLE " & sTableName & " ALTER COLUMN " & sFieldName &
>> > "
>> > MEMO;"
>> > DoCmd.SetWarnings False
>> > DBEngine(0)(0).Execute sSQL, dbFailOnError
>> > DoCmd.SetWarnings True
>> >
>> > If Err.Number = 0 Then Exit Function
>> >
>> > Error_Handler:
>> > MsgBox "MS Access has generated the following error" & vbCrLf &
>> > vbCrLf
>> > &
>> > "Error Number: " & _
>> > Err.Number & vbCrLf & "Error Source: SwitchFieldType" & vbCrLf &
>> > "Error
>> > Description: " & _
>> > Err.Description, vbCritical, "An Error has Occured!"
>> > Exit Function
>> > End Function
>> > --
>> > Hope this helps,
>> >
>> > Daniel Pineault
>> > http://www.cardaconsultants.com/
>> > For Access Tips and Examples: http://www.devhut.net
>> > Please rate this post using the vote buttons if it was helpful.
>> >
>> >
>> >
>> > "Bob Howard" wrote:
>> >
>> >> Hi,
>> >>
>> >> How can I execute a command (presumably using DAO) to change the data
>> >> type
>> >> of an existing table field (and which already contains data) from
>> >> "Text"
>> >> to
>> >> "Memo"?
>> >>
>> >> Thanks in advance...
>> >>
>> >> bob h
>> >>
>> >>
>> >>

>>
>>
>>



 
Reply With Quote
 
Daniel Pineault
Guest
Posts: n/a
 
      13th Mar 2009
Bob,

Don't worry about! As you can see for yourself the required modification to
make it suit your need was absolutely minimal. I was just pulling your leg a
bit.

Have a great day and post back if your need further help.

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



"Bob Howard" wrote:

> Thanks so much ... I'll work on this later tody and post back.
>
> Sorry I didn't initially mention that the database is elsewhere. I had
> already created some code (before I posted), but it was failing with an
> error. I wasn't using SQL to perform the function, but rather I was using
> (what I'll simply call) "other" DAO coding. Like:
>
> Dim daoDatabase as Dao.Database
> Dim daoTableDef as Dao.TableDef
> Dim daoField as Dao.Field
>
> ' the path is passed to this program as a command string
> Set daoDatabase = OpenDatabase(Command)
> Set daoTableDef = daoDatabase.TableDefs("table name")
> Set daoField = daoTableDef("field name")
> daoField.Type = dbMemo
>
> The above fails with error 3219 at the set daoField line.
>
> I copied some code from elsewhere, modified it (to the above) and was hoping
> to make it work (somehow). I'm really a newbie at this type of programming.
>
> bob
>
> "Daniel Pineault" <(E-Mail Removed)> wrote in
> message newsAD8E862-3789-4D7F-BECF-(E-Mail Removed)...
> > You could have mentioned that originally. Not a big thing to modify. Try
> > this instead
> >
> >
> >
> > '---------------------------------------------------------------------------------------
> > ' Procedure : SwitchFieldType
> > ' Author : CARDA Consultants Inc.
> > ' Website : http://www.cardaconsultants.com
> > ' Purpose : Switch a given table field to Memo
> > ' Copyright : The following may be altered and reused as you wish so long
> > as
> > the
> > ' copyright notice is left unchanged (including Author,
> > Website
> > and
> > ' Copyright). It may not be sold/resold or reposted on other
> > sites (links
> > ' back to this site are allowed).
> > '
> > ' Input Variables:
> > ' ~~~~~~~~~~~~~~~~
> > ' sDb - Database Path & Name to execute command against
> > ' sTableName - Name of the Table which has the field to switch
> > ' sFieldName - Name of the field to switch to Memo Type
> > '
> > ' Usage:
> > ' ~~~~~~~~~~~~~~~~
> > ' SwitchFieldType("D:\Contacts\Contacts.mdb","tbl_Contact","Notes")
> > '
> > ' Revision History:
> > ' Rev Date(yyyy/mm/dd) Description
> > '
> > **************************************************************************************
> > ' 1 2009-Mar-13 Initial Release
> > '---------------------------------------------------------------------------------------
> > Function SwitchFieldType(sDb As String, sTableName As String, sFieldName
> > As
> > String)
> > On Error GoTo Error_Handler
> > Dim db As DAO.Database
> > Dim sSQL As String
> >
> > ''Execute the query statement under DAO like this:
> > 'DBEngine(0)(0).Execute sSQL, dbFailOnError
> > ''or under ADO like this:
> > 'CurrentProject.Connection.Execute sSQL
> >
> > Set db = DBEngine.Workspaces(0).OpenDatabase(sDb)
> >
> > sSQL = "ALTER TABLE " & sTableName & " ALTER COLUMN " & sFieldName & "
> > MEMO;"
> >
> > DoCmd.SetWarnings False
> > db.Execute sSQL, dbFailOnError
> > DoCmd.SetWarnings True
> >
> > Set db = Nothing
> >
> > If Err.Number = 0 Then Exit Function
> >
> > Error_Handler:
> > MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf
> > &
> > "Error Number: " & _
> > Err.Number & vbCrLf & "Error Source: SwitchFieldType" & vbCrLf & "Error
> > Description: " & _
> > Err.Description, vbCritical, "An Error has Occured!"
> > Exit Function
> > End Function
> > --
> > Hope this helps,
> >
> > Daniel Pineault
> > http://www.cardaconsultants.com/
> > For Access Tips and Examples: http://www.devhut.net
> > Please rate this post using the vote buttons if it was helpful.
> >
> >
> >
> > "Bob Howard" wrote:
> >
> >> Thanks. I think I see what you're after, but I'm still confused on how
> >> this
> >> code locates the specific DATABASE involved. Actually, I'm going to run
> >> this code to modify the field type (to Memo) for a table located within a
> >> ANOTHER Access database.
> >>
> >> I have a front-end / back-end application, and I need to send a special
> >> Access app to the users of the application that can simply run to modify
> >> their existing back-end database to make this change. Thus, the table
> >> involved is not within the Access database of the running program.
> >>
> >> bob
> >>
> >>
> >> "Daniel Pineault" <(E-Mail Removed)> wrote in
> >> message news:A40D230A-3579-4D31-930C-(E-Mail Removed)...
> >> > Bob,
> >> >
> >> > I put this together rapidly for you. It should do the trick. At the
> >> > very
> >> > least it will show you the basic concept and you can take it from
> >> > there.
> >> > Enjoy!
> >> >
> >> > '---------------------------------------------------------------------------------------
> >> > ' Procedure : SwitchFieldType
> >> > ' Author : CARDA Consultants Inc.
> >> > ' Website : http://www.cardaconsultants.com
> >> > ' Purpose : Switch a given table field to Memo
> >> > ' Copyright : The following may be altered and reused as you wish so
> >> > long
> >> > as
> >> > the
> >> > ' copyright notice is left unchanged (including Author,
> >> > Website
> >> > and
> >> > ' Copyright). It may not be sold/resold or reposted on
> >> > other
> >> > sites (links
> >> > ' back to this site are allowed).
> >> > '
> >> > ' Input Variables:
> >> > ' ~~~~~~~~~~~~~~~~
> >> > ' sTableName - Name of the Table which has the field to switch
> >> > ' sFieldName - Name of the field to switch to Memo Type
> >> > '
> >> > ' Usage:
> >> > ' ~~~~~~~~~~~~~~~~
> >> > ' SwitchFieldType("tbl_Contact","Notes")
> >> > '
> >> > ' Revision History:
> >> > ' Rev Date(yyyy/mm/dd) Description
> >> > '
> >> > **************************************************************************************
> >> > ' 1 2009-Mar-13 Initial Release
> >> > '---------------------------------------------------------------------------------------
> >> > Function SwitchFieldType(sTableName As String, sFieldName As String)
> >> > On Error GoTo Error_Handler
> >> > Dim sSQL As String
> >> >
> >> > ''Execute the query statement under DAO like this:
> >> > 'DBEngine(0)(0).Execute sSQL, dbFailOnError
> >> > ''or under ADO like this:
> >> > 'CurrentProject.Connection.Execute sSQL
> >> >
> >> >
> >> > sSQL = "ALTER TABLE " & sTableName & " ALTER COLUMN " & sFieldName &
> >> > "
> >> > MEMO;"
> >> > DoCmd.SetWarnings False
> >> > DBEngine(0)(0).Execute sSQL, dbFailOnError
> >> > DoCmd.SetWarnings True
> >> >
> >> > If Err.Number = 0 Then Exit Function
> >> >
> >> > Error_Handler:
> >> > MsgBox "MS Access has generated the following error" & vbCrLf &
> >> > vbCrLf
> >> > &
> >> > "Error Number: " & _
> >> > Err.Number & vbCrLf & "Error Source: SwitchFieldType" & vbCrLf &
> >> > "Error
> >> > Description: " & _
> >> > Err.Description, vbCritical, "An Error has Occured!"
> >> > Exit Function
> >> > End Function
> >> > --
> >> > Hope this helps,
> >> >
> >> > Daniel Pineault
> >> > http://www.cardaconsultants.com/
> >> > For Access Tips and Examples: http://www.devhut.net
> >> > Please rate this post using the vote buttons if it was helpful.
> >> >
> >> >
> >> >
> >> > "Bob Howard" wrote:
> >> >
> >> >> Hi,
> >> >>
> >> >> How can I execute a command (presumably using DAO) to change the data
> >> >> type
> >> >> of an existing table field (and which already contains data) from
> >> >> "Text"
> >> >> to
> >> >> "Memo"?
> >> >>
> >> >> Thanks in advance...
> >> >>
> >> >> bob h
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Bob Howard
Guest
Posts: n/a
 
      13th Mar 2009
SUCCESS !

Thanks a "trillion" (I've never used that before...)

bob

"Daniel Pineault" <(E-Mail Removed)> wrote in
message news:0EC5E8C9-70BB-4A99-B117-(E-Mail Removed)...
> Bob,
>
> Don't worry about! As you can see for yourself the required modification
> to
> make it suit your need was absolutely minimal. I was just pulling your
> leg a
> bit.
>
> Have a great day and post back if your need further help.
>
> Daniel Pineault
> http://www.cardaconsultants.com/
> For Access Tips and Examples: http://www.devhut.net
> Please rate this post using the vote buttons if it was helpful.
>
>
>
> "Bob Howard" wrote:
>
>> Thanks so much ... I'll work on this later tody and post back.
>>
>> Sorry I didn't initially mention that the database is elsewhere. I had
>> already created some code (before I posted), but it was failing with an
>> error. I wasn't using SQL to perform the function, but rather I was
>> using
>> (what I'll simply call) "other" DAO coding. Like:
>>
>> Dim daoDatabase as Dao.Database
>> Dim daoTableDef as Dao.TableDef
>> Dim daoField as Dao.Field
>>
>> ' the path is passed to this program as a command string
>> Set daoDatabase = OpenDatabase(Command)
>> Set daoTableDef = daoDatabase.TableDefs("table name")
>> Set daoField = daoTableDef("field name")
>> daoField.Type = dbMemo
>>
>> The above fails with error 3219 at the set daoField line.
>>
>> I copied some code from elsewhere, modified it (to the above) and was
>> hoping
>> to make it work (somehow). I'm really a newbie at this type of
>> programming.
>>
>> bob
>>
>> "Daniel Pineault" <(E-Mail Removed)> wrote in
>> message newsAD8E862-3789-4D7F-BECF-(E-Mail Removed)...
>> > You could have mentioned that originally. Not a big thing to modify.
>> > Try
>> > this instead
>> >
>> >
>> >
>> > '---------------------------------------------------------------------------------------
>> > ' Procedure : SwitchFieldType
>> > ' Author : CARDA Consultants Inc.
>> > ' Website : http://www.cardaconsultants.com
>> > ' Purpose : Switch a given table field to Memo
>> > ' Copyright : The following may be altered and reused as you wish so
>> > long
>> > as
>> > the
>> > ' copyright notice is left unchanged (including Author,
>> > Website
>> > and
>> > ' Copyright). It may not be sold/resold or reposted on
>> > other
>> > sites (links
>> > ' back to this site are allowed).
>> > '
>> > ' Input Variables:
>> > ' ~~~~~~~~~~~~~~~~
>> > ' sDb - Database Path & Name to execute command against
>> > ' sTableName - Name of the Table which has the field to switch
>> > ' sFieldName - Name of the field to switch to Memo Type
>> > '
>> > ' Usage:
>> > ' ~~~~~~~~~~~~~~~~
>> > ' SwitchFieldType("D:\Contacts\Contacts.mdb","tbl_Contact","Notes")
>> > '
>> > ' Revision History:
>> > ' Rev Date(yyyy/mm/dd) Description
>> > '
>> > **************************************************************************************
>> > ' 1 2009-Mar-13 Initial Release
>> > '---------------------------------------------------------------------------------------
>> > Function SwitchFieldType(sDb As String, sTableName As String,
>> > sFieldName
>> > As
>> > String)
>> > On Error GoTo Error_Handler
>> > Dim db As DAO.Database
>> > Dim sSQL As String
>> >
>> > ''Execute the query statement under DAO like this:
>> > 'DBEngine(0)(0).Execute sSQL, dbFailOnError
>> > ''or under ADO like this:
>> > 'CurrentProject.Connection.Execute sSQL
>> >
>> > Set db = DBEngine.Workspaces(0).OpenDatabase(sDb)
>> >
>> > sSQL = "ALTER TABLE " & sTableName & " ALTER COLUMN " & sFieldName &
>> > "
>> > MEMO;"
>> >
>> > DoCmd.SetWarnings False
>> > db.Execute sSQL, dbFailOnError
>> > DoCmd.SetWarnings True
>> >
>> > Set db = Nothing
>> >
>> > If Err.Number = 0 Then Exit Function
>> >
>> > Error_Handler:
>> > MsgBox "MS Access has generated the following error" & vbCrLf &
>> > vbCrLf
>> > &
>> > "Error Number: " & _
>> > Err.Number & vbCrLf & "Error Source: SwitchFieldType" & vbCrLf &
>> > "Error
>> > Description: " & _
>> > Err.Description, vbCritical, "An Error has Occured!"
>> > Exit Function
>> > End Function
>> > --
>> > Hope this helps,
>> >
>> > Daniel Pineault
>> > http://www.cardaconsultants.com/
>> > For Access Tips and Examples: http://www.devhut.net
>> > Please rate this post using the vote buttons if it was helpful.
>> >
>> >
>> >
>> > "Bob Howard" wrote:
>> >
>> >> Thanks. I think I see what you're after, but I'm still confused on
>> >> how
>> >> this
>> >> code locates the specific DATABASE involved. Actually, I'm going to
>> >> run
>> >> this code to modify the field type (to Memo) for a table located
>> >> within a
>> >> ANOTHER Access database.
>> >>
>> >> I have a front-end / back-end application, and I need to send a
>> >> special
>> >> Access app to the users of the application that can simply run to
>> >> modify
>> >> their existing back-end database to make this change. Thus, the table
>> >> involved is not within the Access database of the running program.
>> >>
>> >> bob
>> >>
>> >>
>> >> "Daniel Pineault" <(E-Mail Removed)> wrote in
>> >> message news:A40D230A-3579-4D31-930C-(E-Mail Removed)...
>> >> > Bob,
>> >> >
>> >> > I put this together rapidly for you. It should do the trick. At
>> >> > the
>> >> > very
>> >> > least it will show you the basic concept and you can take it from
>> >> > there.
>> >> > Enjoy!
>> >> >
>> >> > '---------------------------------------------------------------------------------------
>> >> > ' Procedure : SwitchFieldType
>> >> > ' Author : CARDA Consultants Inc.
>> >> > ' Website : http://www.cardaconsultants.com
>> >> > ' Purpose : Switch a given table field to Memo
>> >> > ' Copyright : The following may be altered and reused as you wish so
>> >> > long
>> >> > as
>> >> > the
>> >> > ' copyright notice is left unchanged (including Author,
>> >> > Website
>> >> > and
>> >> > ' Copyright). It may not be sold/resold or reposted on
>> >> > other
>> >> > sites (links
>> >> > ' back to this site are allowed).
>> >> > '
>> >> > ' Input Variables:
>> >> > ' ~~~~~~~~~~~~~~~~
>> >> > ' sTableName - Name of the Table which has the field to switch
>> >> > ' sFieldName - Name of the field to switch to Memo Type
>> >> > '
>> >> > ' Usage:
>> >> > ' ~~~~~~~~~~~~~~~~
>> >> > ' SwitchFieldType("tbl_Contact","Notes")
>> >> > '
>> >> > ' Revision History:
>> >> > ' Rev Date(yyyy/mm/dd) Description
>> >> > '
>> >> > **************************************************************************************
>> >> > ' 1 2009-Mar-13 Initial Release
>> >> > '---------------------------------------------------------------------------------------
>> >> > Function SwitchFieldType(sTableName As String, sFieldName As String)
>> >> > On Error GoTo Error_Handler
>> >> > Dim sSQL As String
>> >> >
>> >> > ''Execute the query statement under DAO like this:
>> >> > 'DBEngine(0)(0).Execute sSQL, dbFailOnError
>> >> > ''or under ADO like this:
>> >> > 'CurrentProject.Connection.Execute sSQL
>> >> >
>> >> >
>> >> > sSQL = "ALTER TABLE " & sTableName & " ALTER COLUMN " & sFieldName
>> >> > &
>> >> > "
>> >> > MEMO;"
>> >> > DoCmd.SetWarnings False
>> >> > DBEngine(0)(0).Execute sSQL, dbFailOnError
>> >> > DoCmd.SetWarnings True
>> >> >
>> >> > If Err.Number = 0 Then Exit Function
>> >> >
>> >> > Error_Handler:
>> >> > MsgBox "MS Access has generated the following error" & vbCrLf &
>> >> > vbCrLf
>> >> > &
>> >> > "Error Number: " & _
>> >> > Err.Number & vbCrLf & "Error Source: SwitchFieldType" & vbCrLf &
>> >> > "Error
>> >> > Description: " & _
>> >> > Err.Description, vbCritical, "An Error has Occured!"
>> >> > Exit Function
>> >> > End Function
>> >> > --
>> >> > Hope this helps,
>> >> >
>> >> > Daniel Pineault
>> >> > http://www.cardaconsultants.com/
>> >> > For Access Tips and Examples: http://www.devhut.net
>> >> > Please rate this post using the vote buttons if it was helpful.
>> >> >
>> >> >
>> >> >
>> >> > "Bob Howard" wrote:
>> >> >
>> >> >> Hi,
>> >> >>
>> >> >> How can I execute a command (presumably using DAO) to change the
>> >> >> data
>> >> >> type
>> >> >> of an existing table field (and which already contains data) from
>> >> >> "Text"
>> >> >> to
>> >> >> "Memo"?
>> >> >>
>> >> >> Thanks in advance...
>> >> >>
>> >> >> bob h
>> >> >>
>> >> >>
>> >> >>
>> >>
>> >>
>> >>

>>
>>
>>



 
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 Data Type from Memo to Text rscott927 Microsoft Access VBA Modules 3 9th Dec 2009 09:17 PM
Memo Field - Append Text fields into memo field??? =?Utf-8?B?UGF0IFN0ZXdhcnQ=?= Microsoft Access 1 18th Feb 2007 08:45 PM
memo field on the form-- text wrapped/ text unwrapped DiDi Microsoft Access Forms 1 5th Feb 2007 04:05 PM
trouble concatenating text of 1 memo field to another memo field in same record via button ghadley_00@yahoo.com Microsoft Access Form Coding 1 9th Nov 2005 11:55 AM
Re: Change TEXT to MEMO field? chas Microsoft Access Macros 1 5th Aug 2003 11:09 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:08 AM.