Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Create table with DAO at run-time and set date field formate

$
0
0
Hello everyone, I'm using an Access database with DAO, I used to create some tables at run-time using the method DB.Execute with SQL and it was all fine until I had a problem with date fields when I was exporting data to Excel file, Excel is switching the "dd-mm-yyyy" format to "mm-dd-yyyy" format in some cells and not all, I tried all the possible solutions like the Format() function, change the date format from the control panel and changing the cell format from within Excel and the problem still exists, I thought of another solution which is to change the database field format from "dd-mm-yyyy" to "dd-mmmm-yyyy". Now the question is how to create table at run-time that has a date type field that has "dd-mmmm-yyyy" format, I found another method as follows but couldn't make it

Dim db As DAO.Database
    Dim tdf As DAO.TableDef
    Dim fld As DAO.Field
    
    'Initialize the Contractor table.
    Set db = CurrentDb()
    Set tdf = db.CreateTableDef("tblDaoContractor")
    
    'Specify the fields.
    With tdf   
        'Text field: maximum 30 characters, and required.
        Set fld = .CreateField("Surname", dbText, 30)
        fld.Required = True
        .Fields.Append fld
        
        'Text field: maximum 20 characters.
        .Fields.Append .CreateField("FirstName", dbText, 20)
        
        'Yes/No field.
        .Fields.Append .CreateField("Inactive", dbBoolean)
        
        'Currency field.
        .Fields.Append .CreateField("HourlyFee", dbCurrency)
        
        'Number field.
        .Fields.Append .CreateField("PenaltyRate", dbDouble)
        
        'Date/Time field with validation rule.
        Set fld = .CreateField("BirthDate", dbDate)
        fld.ValidationRule = "Is Null Or <=Date()"
        fld.ValidationText = "Birth date cannot be future."
        .Fields.Append fld
        
        'Memo field.
        .Fields.Append .CreateField("Notes", dbMemo)
        
        'Hyperlink field: memo with the attribute set.
        Set fld = .CreateField("Web", dbMemo)
        fld.Attributes = dbHyperlinkField + dbVariableField
        .Fields.Append fld
    End With
    
    'Save the Contractor table.
    db.TableDefs.Append tdf
    Set fld = Nothing
    Set tdf = Nothing




THANKS IN ADVANCE

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>