Advertisement

07.05.2008 at 08:24AM PDT, ID: 23540707
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.7

How do I programmatically change an existing Field's data type?

Asked by bobbat in Access Forms, Microsoft Access Database

I use the attached code snippet to change field names and, optionally, to change the field's description.  How can I modify the code below to optionally change the field's data type too?  Assume there are no errors in the data conversion.  For example, an existing field labeled strMyTextField, only has numbers and I want to change it to the Integer data type and rename it intMyTextField.  In other words, when I change the data type manually in table design view from Text to Number, there are no errors.  The DAO Field type reference, i.e. the Constant names and Decimal values are shown below (source: http://allenbrowne.com/ser-49.html):
DAO constant                       DAO Decimal
dbBoolean                                1
dbByte                                2
dbInteger                                3
dbLong                                4
dbCurrency                                5
dbSingle                                6
dbDouble                                7
dbDate                                8
dbBinary                                9
dbText                               10
dbLongBinary                               11
dbMemo                               12
dbMemo with attributes              12
dbGUID                               15
dbDecimal                               20
dbAttachment                                101
dbComplexByte                                102
dbComplexInteger      103
dbComplexLong                                 104
dbComplexSingle      105
dbComplexDouble      106
dbComplexGUID                                 107
dbComplexDecimal      108
dbComplexText                                 109Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
Public Function ChangeFieldName(strTableName As String, strOldFieldName As String, strNewFieldName As String, Optional strNewFieldDescription As String)      
    Dim db As DAO.Database
    Dim tdf As DAO.TableDef
    Dim prp As Property
    
    Set db = CurrentDb
    Set tdf = db.TableDefs(strTableName)
    
    On Error GoTo ErrHandler
    
    If Not IsNull(strNewFieldDescription) And strNewFieldDescription <> "" Then
        With tdf.Fields(strOldFieldName)
            .Properties("Description").Value = strNewFieldDescription
        End With
    End If
    
    tdf(strOldFieldName).Name = strNewFieldName
   
ErrHandler:
    Select Case Err
            
        Case 3265&  'Table or Field name invalid
            MsgBox tdf.Name & " table or field doesn't exist"
                
        Case 3270
            tdf.Fields(strOldFieldName).Properties.Append _
            tdf.Fields(strOldFieldName).CreateProperty("Description", dbText, strNewFieldDescription)
            
            tdf(strOldFieldName).Name = strNewFieldName
    
            Err.Clear
                        
        Case Else
            Debug.Print "    AppendDeleteField() Error " & Err & ": " & Error
    End Select
   
    Set prp = Nothing
    Set tdf = Nothing
    Set db = Nothing
End Function
[+][-]07.05.2008 at 08:40AM PDT, ID: 21937382

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.05.2008 at 08:47AM PDT, ID: 21937395

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Access Forms, Microsoft Access Database
Sign Up Now!
Solution Provided By: capricorn1
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.05.2008 at 08:49AM PDT, ID: 21937399

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.05.2008 at 08:50AM PDT, ID: 21937406

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.05.2008 at 01:14PM PDT, ID: 21938208

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628