Solved

Checking is_required property of ms access table fields

Posted on 2008-10-26
1
512 Views
Last Modified: 2013-11-29
Hi,
Im using the following code for checking the 'nullable' property of ms access table fields with name 'tablename' and field 'fieldname' passed as variables to the function and returning 'NOT NULL' string. The function should check if the field is a 'is_required' field type.
Unfortunately, Im not getting the desired result ie. Primary key fields dont return a 'NOT NULL'. Any idea why this might be? Any help will be much appreciated

function GetRequired(ADOConnection: TADOConnection; tablename:string; fieldname:string):string;

var

fieldreq: TADODataSet;

i: integer;

comparefield: integer;

output: boolean;

begin

  fieldreq := TADODataSet.Create(nil);

  fieldreq.Connection := ADOConnection;

try

ADOConnection.OpenSchema(siColumns,VarArrayOf([Unassigned,Unassigned,tablename,Unassigned]),EmptyParam,fieldreq);
 

for i := 0 to fieldreq.RecordCount-1 do

  begin

comparefield :=AnsiCompareStr(fieldreq.FieldByName('COLUMN_NAME').AsString, fieldname);

if comparefield = 0 then begin

output := fieldreq.FieldByName('IS_NULLABLE').AsBoolean;

  if output

    then fieldreq.Next

  else result := 'NOT NULL';

end

else

fieldreq.Next;

end;

finally

fieldreq.Free;

end;

end;

Open in new window

0
Comment
Question by:sbahri
1 Comment
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 125 total points
ID: 22810450
sbahri,

Primary keys, by design, cannot be null.
So even if you set the Required property to No, you will not be able to leave it blank.
So you may want to somehow exclude/ignore them in your code.

JeffCoachman
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now