Results 1 to 1 of 1

Thread: How to add feild size and null constraint check to this vba

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Arrow How to add feild size and null constraint check to this vba

    Hi guys. I have a program that i want to add feild size and null constraint check on it and make it work on accesss 2000 . I be happy if some one help me modify this code so it generate Acess sql statements so that i be able to paste it in sql window of acces 2000 and it excutes. .Thanks

    On click event that i used to call this function

    Code:
    For Each T In db.TableDefs
        '''Skip the system tables
            If Left(T.Name, 4) <> "MSys" Then
           
               
               ''' this line determines the primary key of the table
               ''' by calling GetPk function from module
               
                    pk = Left(GetPK(T, db), InStr(1, GetPK(T, db), "<-") - 1)
                    
                    cont = cont & ShowFields(T.Name) & vbCrLf & " primary key " & pk & vbCrLf & vbCrLf
                   
                  
            End If
        Next T
        
        ''' This line of code post the generated table statment to a massage box
        
        MsgBox cont
    Code:
    Function ShowFields(pTable As String) As String
    
    Dim db As Database
    Dim rs As Recordset
    Dim I As Integer
    Dim j As Integer
    Dim n As Integer
    Dim NL As String
    Dim strHold As String, ST As String
    Dim x As Variant
    
    NL = Chr(13) & Chr(10) ' Define newline.
    
    Set db = CurrentDb
    
    Set rs = db.OpenRecordset(pTable)
    
    n = rs.Fields.Count
    ReDim x(n - 1, 1) As String
    
    
    ST = "Create Table " & pTable & vbCrLf
    For I = 0 To (n - 1)
    
    ST = ST & rs.Fields(I).Name & " " & FieldType(rs.Fields(I).Type) & "," & vbCrLfNext I
    rs.Close
    db.Close
    Set db = Nothing
    
    ShowFields = ST '' returns the fields name to main function
    End Function
    Last edited by tony007; Aug 17th, 2005 at 03:36 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width