Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Checking is_required property of ms access table fields

Posted on 2008-10-26
1
Medium Priority
?
525 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 375 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

730 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