473,289 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

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.Attributes And adFldIsNullable Then
Required = 0 'field is NOT required
Else
Required = 1 'field is required
End If

strFieldRequired = strFieldRequired & 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 strFieldRequired:
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 2975
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*****@mysurname.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.Attributes And adFldIsNullable Then
Required = 0 'field is NOT required
Else
Required = 1 'field is required
End If

strFieldRequired = strFieldRequired & 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 strFieldRequired:
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***@TRASHaspfaq.com> ha scritto nel messaggio
news:uJ**************@TK2MSFTNGP09.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.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.Mappath("\xxxy\datasource\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.2024@tkmsftngp04 on
microsoft.public.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***@TRASHaspfaq.com> ha scritto nel
messaggio news:uJ**************@TK2MSFTNGP09.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.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.Mappath("\xxxy\datasource\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.2024@tkmsftngp04 on microsoft.public.data.ado

Jul 19 '05 #4
"Bob Barrows" <re******@NOyahoo.SPAMcom> ha scritto nel messaggio
news:Ot**************@TK2MSFTNGP10.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***@TRASHaspfaq.com> ha scritto nel messaggio
news:uJ**************@TK2MSFTNGP09.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("tblAuthor"), cnn, adOpenDynamic, adLockOptimistic,
adCmdTableDirect

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

strFieldRequired = strFieldRequired & 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!! ;-)
adCmdTableDirect 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
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...
10
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...
16
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...
3
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...
7
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:...
9
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...
2
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...
3
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...
1
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.