Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Database Access / September 2004



Tip: Looking for answers? Try searching our database.

Required Fields in a Recordset

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Wright - 29 Sep 2004 18:14 GMT
I have a standalone recordset that my class object passes to the caller to
be filled out and returned.  This ensures that my class receives the data in
a format that can be easily worked with.  The following is the code to
created the recordset:

Public Function GetInvoiceItemRS() As Recordset
On Error GoTo GetInvoiceItemRSError:
Set GetInvoiceItemRS = New Recordset
With GetInvoiceItemRS
   .Fields.Append "ItemLineNumber", adInteger
   .Fields.Append "LineItem", adVarChar, 6
   .Fields.Append "NationalStockNumber", adVarChar, 17
   .Fields.Append "ProductType", adVarChar, 2
   .Fields.Append "ItemDescription", adVarChar, 1875
   .Fields.Append "GFE", adVarChar, 1
   .Fields.Append "ACRN", adVarChar, 2
   .Fields.Append "MILSTRIP", adVarChar, 15
   .Fields.Append "MILSTRIPQTY", adVarChar, 6
   .Fields.Append "QTY", adVarChar, 11
   .Fields.Append "ShipCode", adVarChar, 1
   .Fields.Append "UofM", adVarChar, 2
   .Fields.Append "UnitPrice", adCurrency, 16
End With

Exit Function
GetInvoiceItemRSError:

End Function

Is there a way to indicate which fields are required in this recordset as I
pass it to the client?  I need to make sure that certain fields are filled
out and would like client to be aware of the required fields as they fill
them out and before they are sent back to the class for validation.  Thanks.

John
Hoa - 29 Sep 2004 19:56 GMT
Check attrib parameter:
Attrib   Optional. A FieldAttributeEnum, whose default value is
adFldDefault. Specifies attributes for the new field. If this value is not
specified, the field will contain attributes derived from Type.

HTH

Hoa

> I have a standalone recordset that my class object passes to the caller to
> be filled out and returned.  This ensures that my class receives the data in
[quoted text clipped - 31 lines]
>
> John
John Wright - 29 Sep 2004 20:00 GMT
So if I checked the attrib parameter and found it to say "No nulls allowed"
then the client would know this was a required field?  Could you provide an
example.

Thanks.

John
> Check attrib parameter:
> Attrib   Optional. A FieldAttributeEnum, whose default value is
[quoted text clipped - 43 lines]
> >
> > John
Val Mazur - 30 Sep 2004 04:22 GMT
Hi John,

Even though when you create the field in ADO recordset, you could specify
attributes for it, I did not see any attribute which say that field cannot
be null or require one. There is adFldIsNullable attribute, but nothing
opposite. Maybe someone has more information about it

Signature

Val Mazur
Microsoft MVP

>I have a standalone recordset that my class object passes to the caller to
> be filled out and returned.  This ensures that my class receives the data
[quoted text clipped - 34 lines]
>
> John
Hoa - 30 Sep 2004 18:19 GMT
Hi *.*

Yes, there is no opposite for adFldIsNullable so there is no way to control
the data in client just in updating the Recordset. (No error occurs in
update because VB doesn't know which field is Nullable)

But you can control this with a simple procedure in Client Lick This:

   Function DoUpdate(Rst As Recordset) As Integer
  Dim Fld As Field
  For Each Fld In Rst.Fields
     If Not CBool(Fld.Attributes And adFldIsNullable) And IsEmpty(Fld) Then
        'Your Error Statement
        DoUpdate = -1            'Means Error
        Exit Function
     End If
  Next

  Rst.Update
End Function

Now, you need to add adFldIsNullable to the Nullable fields,

HTH
Hoa
Hoa - 30 Sep 2004 18:25 GMT
Function DoUpdate(Rst As Recordset) As Integer
  Dim Fld As Field
  For Each Fld In Rst.Fields
     If Not (Fld.Attributes And adFldIsNullable) And IsEmpty(Fld) Then
        'Your Error Statement
        MsgBox Fld.Name & " is not nullable!", vbInformation, "Update
Failed..."
        DoUpdate = -1            'Means Error
        Exit Function
     End If
  Next

  Rst.Update
End Function

Sorry, but I've forgot to omit the CBool in my previous reply,

HTH
Hoa
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.