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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to add a database field in a startup script 1

Status
Not open for further replies.

marcello62

Technical User
Jun 19, 2006
42
NL
Hi there,

I'm wondering if it is possible to use some kind of option in a shortcut command to add a column to a Microsoft Access database. Maybe there is startup parameter to accomplish this?

Any help will be greatly appreciated, Thanks.
 
You can specify a macro to run in the command line. If you don't have a macro or autoexec code in the system to create the field in the table (not to a database) you can't do it.

Why?

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Thanks dhookom,

I considered that also, the point is that the script is to run only once. Is there any possibility to have the script I want to run invoked only once? So, the autoexec should check for the existence of some table-column, in my particular case...
 
This function will tell you whether a specified field exists in a particular table:

Code:
Public Function FieldExists(ByVal strTableName As String, ByVal strFieldName As String) As Boolean
    Dim ThisDB As DAO.Database
    Dim TDef As DAO.TableDef
    Dim MyField As DAO.Field
    
    Set ThisDB = CurrentDb()
    Set TDef = ThisDB.TableDefs(strTableName)
    
    For Each MyField In TDef.Fields
        If MyField.Name = strFieldName Then
            FieldExists = True
            Exit For
        End If
    Next MyField

    Set MyField = Nothing
    Set TDef = Nothing
    
    ThisDB.Close
    Set ThisDB = Nothing
End Function

You can determine whether or not to create the field depending on the return value of the function.

Ed Metcalfe.

Please do not feed the trolls.....
 
Thanks Ed2020,

Looks great! Gonna try it right away.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top