Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 17th, 2005, 04:21 AM
Friend of Wrox
 
Join Date: Mar 2005
Posts: 264
Thanks: 0
Thanked 0 Times in 0 Posts
Default Error checking for table fields null value constra

Error checking for table fields null value constraint

Hi all. I want to check for not null value constraint for all tables in database . I tried the following but when i run it i get the following error:

Compile error:
Invalid Next control variable reference

I be happy if some one one help me fix this error.if i remove the bold lines the program workes well but it does not put not null for table fileds that requries value.

picture of the output without the bold part

http://i5.photobucket.com/albums/y18...07/notnull.jpg


Code:
Option Compare Database

''This module displays field name and type in a massage box
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
''adding Create table and table name to statement
ST = "Create Table " & pTable & vbCrLf & "("

For I = 0 To (n - 1)

For Each fld In tbl.Fields 

ST = ST & rs.Fields(I).Name & " " & FieldType(rs.Fields(I).Type) & "," & vbCrLf


               If fld.Required = True Then
                  ST = ST & " NOT NULL" & " "
               Else
                  ST = ST
               End If


Next I
rs.Close
db.Close
Set db = Nothing

ShowFields = ST '' returns the fields name to main function
End Function
on click even code

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
 
Old September 26th, 2005, 09:00 PM
Authorized User
 
Join Date: Oct 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

For now, to get around the error message that you're getting:

Put a "Next fld" on the line before the "Next I".

The compiler cannot find the end of the "For Each fld" loop,
and therefore, produced the error.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking for Null ~Bean~ BOOK: Beginning ASP 3.0 2 June 27th, 2005 07:09 AM
Checking for Null Values asmodeus BOOK: Beginning VB.NET Databases 2 June 3rd, 2005 03:18 PM
Checking null values in Query(SQL Server) Prob leo_vinay Classic ASP Databases 2 December 28th, 2004 04:31 AM
checking fields value from rs lucian Dreamweaver (all versions) 4 July 24th, 2004 02:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.