Solved

Checking is_required property of ms access table fields

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
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…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

820 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