473,587 Members | 2,230 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Detecting if a field is required

Hi all,

i need to detect whether a field is required or not. I'm using this code for
building a string to convert later to an array (by Split) of which each
element matches the field index (ex. Field(myArray(0 )):

For Each Field in rst.Fields
If Field.Attribute s And adFldIsNullable Then
Required = 0 'field is NOT required
Else
Required = 1 'field is required
End If

strFieldRequire d = strFieldRequire d & Required & " "
Next

I'm running the above code against a table which has 4 fields in this exact
order:
- a PK
- 2 required text fields
- 1 NOT required text field

And i'm getting this result when printing strFieldRequire d:
1 0 0 0

So what's the problem with the code above? I've got some inspiration from
the script at this URL:
http://www.asptechniques.com/content.asp?a=co&cID=910

Thank You,
Lorenzo
Jul 19 '05 #1
5 2992
Make sure you are using OLEDB to connect to your database; adFldIsNullable
is not exposed to the standard ODBC/JET drivers. To see an OLEDB connection
string, see http://www.aspfaq.com/2126 and make sure you have a recent
installation of MDAC.

"Lorenzo Bolognini" <lo*****@mysurn ame.net> wrote in message
news:5L******** **************@ news1.tin.it...
Hi all,

i need to detect whether a field is required or not. I'm using this code for building a string to convert later to an array (by Split) of which each
element matches the field index (ex. Field(myArray(0 )):

For Each Field in rst.Fields
If Field.Attribute s And adFldIsNullable Then
Required = 0 'field is NOT required
Else
Required = 1 'field is required
End If

strFieldRequire d = strFieldRequire d & Required & " "
Next

I'm running the above code against a table which has 4 fields in this exact order:
- a PK
- 2 required text fields
- 1 NOT required text field

And i'm getting this result when printing strFieldRequire d:
1 0 0 0

So what's the problem with the code above? I've got some inspiration from
the script at this URL:
http://www.asptechniques.com/content.asp?a=co&cID=910

Thank You,
Lorenzo

Jul 19 '05 #2
"Aaron Bertrand [MVP]" <aa***@TRASHasp faq.com> ha scritto nel messaggio
news:uJ******** ******@TK2MSFTN GP09.phx.gbl...
Make sure you are using OLEDB to connect to your database; adFldIsNullable
is not exposed to the standard ODBC/JET drivers. To see an OLEDB connection string, see http://www.aspfaq.com/2126 and make sure you have a recent
installation of MDAC.


The following is my connection string and i'm using ADO 2.8 on a Win2k with
ALL the latest patches:

cnn.ConnectionS tring = "Provider=Micro soft.Jet.OLEDB. 4.0;" & _
"Data Source=" & Server.Mappath( "\xxxy\datasour ce\xyz.mdb") & _
";Persist Security Info=False"

I'm noticing that someone else has had the same problem always with Access
as you may see if you look for this MsgID: uGwIzjTjBHA.202 4@tkmsftngp04 on
microsoft.publi c.data.ado

Thank You,
Lorenzo

P.S I live by aspfaq.com and i couldn't stress enough how much i'm thankfull
to you!
Jul 19 '05 #3
When I think back to the dozens of Access applications I've created, and the
single ASP application I've created that used Access, I can safely say that
I've never onec had to worry about whether a field was "Required" or not.
The reason: I never created a nullable field. And even when i was using a
database created by someone else, I did not care: I always put a default
value into all fields. Instead of wasting devlopment and processing time
with code code that tests the nullability of the fields in your table, start
with the assumption that they are all required.

Having said that, I'm wondering if you realize that an Access Text field can
be created with the Required checkbox unchecked, but the "Allow zero-length
string" checkbox unchecked, a contidtion which will not be covered in the
Attributes property since it's a Jet-specific property.

Bob Barrows

Lorenzo Bolognini wrote:
"Aaron Bertrand [MVP]" <aa***@TRASHasp faq.com> ha scritto nel
messaggio news:uJ******** ******@TK2MSFTN GP09.phx.gbl...
Make sure you are using OLEDB to connect to your database;
adFldIsNullable is not exposed to the standard ODBC/JET drivers. To
see an OLEDB connection string, see http://www.aspfaq.com/2126 and
make sure you have a recent installation of MDAC.


The following is my connection string and i'm using ADO 2.8 on a
Win2k with ALL the latest patches:

cnn.ConnectionS tring = "Provider=Micro soft.Jet.OLEDB. 4.0;" & _
"Data Source=" & Server.Mappath( "\xxxy\datasour ce\xyz.mdb") &
_ ";Persist Security Info=False"

I'm noticing that someone else has had the same problem always with
Access as you may see if you look for this MsgID:
uGwIzjTjBHA.202 4@tkmsftngp04 on microsoft.publi c.data.ado

Jul 19 '05 #4
"Bob Barrows" <re******@NOyah oo.SPAMcom> ha scritto nel messaggio
news:Ot******** ******@TK2MSFTN GP10.phx.gbl...
Having said that, I'm wondering if you realize that an Access Text field can be created with the Required checkbox unchecked, but the "Allow zero-length string" checkbox unchecked, a contidtion which will not be covered in the
Attributes property since it's a Jet-specific property.


Thank You very much but that would be a workaround and i think i cannot rely
on that since i'm building a function for:
- displaying all rows in a table and allowing inserts, edit and delete of
records in that table
- building a for with ready-made javascript (on the client side) and server
controls based on the field attributes

Making it the way u say may work for MY db but not on someone elses which i
may not be allowed to modify if i want to reuse my function.

Anyway thank you very much for pointing that out.

Lorenzo
Jul 19 '05 #5
"Aaron Bertrand [MVP]" <aa***@TRASHasp faq.com> ha scritto nel messaggio
news:uJ******** ******@TK2MSFTN GP09.phx.gbl...
Make sure you are using OLEDB to connect to your database; adFldIsNullable
is not exposed to the standard ODBC/JET drivers. To see an OLEDB connection string, see http://www.aspfaq.com/2126 and make sure you have a recent
installation of MDAC.


I've finally made it this way:

rst.Open("tblAu thor"), cnn, adOpenDynamic, adLockOptimisti c,
adCmdTableDirec t

For Each Field in rst.Fields
If Field.Attribute s And adFldIsNullable Then
Required = 0 'nullable
Else
Required = 1 'not nullable
End If

strFieldRequire d = strFieldRequire d & Required & " "
Next

I've played only with the ADO CommandTypeEnum i don't know if chainging the
cursors may affect in any way the results but THIS way it works!! ;-)
adCmdTableDirec t is is the only CommandTypeEnum which returns the right
results

Think this could be placed on the aspfaq.com

Lorenzo

Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
17165
by: Gav | last post by:
Hi, At the moment i am checking that all the fields have been filled out, at the moment i am using the following... if firstname = "" and surname = "" and address1 = "" and town = "" and county = "" and country = "" and postcode = "" and phone = "" and email11 = "" and email2 = "" and password1 = "" and password2 = "" then is there a...
10
4106
by: Frances Del Rio | last post by:
pls, why is this not working? <SCRIPT language=JavaScript type="text/javascript"> var br = '<SCRIPT language=Javascript' br += 'src="js_pop.js" type="text/javascript">' br += '</SCRIPT>' var op = '<SCRIPT language=Javascript' op += 'src="js_pop-op.js" type="text/javascript">' op += '</SCRIPT>' if (navigator.userAgent.indexOf('Opera') !=...
16
8469
by: Georges Heinesch | last post by:
Hi. My form contains a control (cboFooBar), which has an underlying field with the "Required" property set to "Yes". Now, while filling out all the controls of the form, I have to fill out this particular (required) control as well. However further down the form, there is another control, which has to (under certain conditions) to delete...
3
2930
by: Orchid | last post by:
Hello All, Hope someone can help me on my required field problems. I have a form base on a table for users to input new Employees. There are 4 fields that cannot be Null when entering new records. (but on the table, I have these 4 field set up as "Required = No"). I want the codes to be able to check if the 4 fields are null, if is null,...
7
2338
by: fox | last post by:
Maybe this is not the best group to ask this question, but I don't know a better one. I'm looking for a *portable* program in C (I mean source code) to detect whether unaligned word access is: a. handled by the main processor (e.g. x86) b. not supported (e.g. Sparc running Solaris) c. emulated in software (e.g. Alpha running Linux) By...
9
2009
by: D. Shane Fowlkes | last post by:
I'm using SQL Server 2000 and on my page, I'm simply creating a SQLDataReader and filling in Labels with the retrieved (single) record. However, how can I prevent from getting errors when a field is null? I've tried something like this (experimenting with IsDBNull): ========================================================= If...
2
1395
by: Simon Harvey | last post by:
Hi all, Is there any easy way to check a field for calues that have changed on a post back. So the page is sent to the user, the user changes some values and I need to know which ones changed. Is the only way to do this to go through all the fields and check them against their old values. In which case, would I need to store the values...
3
3605
by: regtrashcan | last post by:
I have a webpage that detects whether Shockwave Player is installed and the version number. The javascript/vbscript that I use has worked fine until the latest release of the Shockwave Player. I am still able to detect the Shockwave Player and the version number when using Firefox/Netscape, but not with IE. I have my own detection script that...
1
3947
by: gtwannabe | last post by:
I'm having a problem with a form that uses AutoNumber as the primary key. I have an Abort button to delete the current record and close the form. If AutoNumber is assigned, the code executes a SQL statement that deletes the current record. I need to be able to detect when AutoNumber is unassigned (a new blank record) so that I can simply...
0
8205
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5712
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2347
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.