Solved

Checking is_required property of ms access table fields

Posted on 2008-10-26
1
515 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

914 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

21 Experts available now in Live!

Get 1:1 Help Now