Sign Up |  Live StatsLive Stats    Articles 35,345| Comments 159,788| Members 17,820, Newest waheguruhelpme| Online 224
Home Contact
 (Forgotten?): 
    Sikhism

   
                                                                     Your Banner Here!    

Sikh Philosophy Network » Sikh Philosophy Network » Current Affairs » Information Technology » Delete only specific field in record to Null

Delete only specific field in record to Null

Our Donation Goal : Why Donate? : Donate Today! : Donate Anonymously (ਗੁਪਤ) : Our Family of Supporters
Goal this month: 400 USD, Received: 35 USD (9%)
Please Donate...
Related Topics...
Thread Thread Starter Forum Replies Last Post
problems deleting a specific record andriulli@gmail.com Information Technology 8 28-Jul-2006 08:42 AM
Open combo box to specific record Economics Information Technology 4 28-Jul-2006 08:31 AM
problem displaying specific record MartinR Information Technology 10 28-Jul-2006 08:31 AM
problem displaying specific record martin.ryan@esbi.ie Information Technology 0 28-Jul-2006 08:30 AM
RE: print a specific record Ofer Cohen Information Technology 0 28-Jul-2006 07:59 AM


Tags
delete, specific, field, record, null
Reply Post New Topic In This Forum Stay Connected to Sikhism, Click Here to Register Now!
  #1 (permalink)  
Old 28-Jul-2006, 08:20 AM
Gina's Avatar Gina
Guest
 
Posts: n/a
   
   
Delete only specific field in record to Null

  Donate Today!   Email to Friend  Tell a Friend   Show Printable Version  Print   Contact sikhphilosophy.net Administraion for any Suggestions, Ideas, Feedback.  Feedback  

Register to Remove Advertisements
All,

In the following SQL script I am trying to blank out the fields, but so far
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/information-technology/11361-delete-only-specific-field-record-null.html
it isn't working. Can you point me in the right direction.

Thanks!

'Setup the table and recordset to be edited

' strTablename = "Billing"

Set db = CurrentDb
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=11361

Set rst = db.OpenRecordset(strTableName, dbOpenDynaset)



For Each i In Me![lstItems].ItemsSelected 'Determine the number of items
selected in the list

Criteria = Me![lstItems].ItemData(i) 'Assign the Customer Number a
variable



With rst

.MoveFirst

.FindFirst "[ID] = " & Criteria & "" 'Locate a Customer Number that
matches the one selected from the list

.Edit

.Fields("Assigned") = 0 'Uncheck the checkbox

.Fields("AssignedTo") = "" 'Clear the person's name from the record

.Fields("DateAssigned").Value = "" 'Clear the Assign date

.Update

End With

rst.Close

Next i 'Loop through the next record

Set db = Nothing 'Unset the Database

Set rst = Nothing 'Unset the recordset



Me.lstItems.Requery

Exit Sub


--
Gina



 
Do share your immediate thoughts or reactions on this issue? We value your views! Login Now! or Sign Up Today! to share your views with us.. Gurfateh!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 28-Jul-2006, 08:20 AM
Gina's Avatar Gina
Guest
 
Posts: n/a
   
   
RE: Delete only specific field in record to Null

Sorry, only the date field doesn't work.
--
Gina


"Gina" wrote:

> All,
>
> In the following SQL script I am trying to blank out the fields, but so far
> it isn't working. Can you point me in the right direction.
>
> Thanks!
>
> 'Setup the table and recordset to be edited
>
> ' strTablename = "Billing"
>
> Set db = CurrentDb
>
> Set rst = db.OpenRecordset(strTableName, dbOpenDynaset)
>
>
>
> For Each i In Me![lstItems].ItemsSelected 'Determine the number of items
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=11361
> selected in the list
>
> Criteria = Me![lstItems].ItemData(i) 'Assign the Customer Number a
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=11361
> variable
>
>
>
> With rst
>
> .MoveFirst
>
> .FindFirst "[ID] = " & Criteria & "" 'Locate a Customer Number that
> matches the one selected from the list
>
> .Edit
>
> .Fields("Assigned") = 0 'Uncheck the checkbox
>
> .Fields("AssignedTo") = "" 'Clear the person's name from the record
>
> .Fields("DateAssigned").Value = "" 'Clear the Assign date
>
> .Update
>
> End With
>
> rst.Close
>
> Next i 'Loop through the next record
>
> Set db = Nothing 'Unset the Database
>
> Set rst = Nothing 'Unset the recordset
>
>
>
> Me.lstItems.Requery
>
> Exit Sub
>
>
> --
> Gina

Reply With Quote
  #3 (permalink)  
Old 28-Jul-2006, 08:20 AM
Graham Mandeno's Avatar Graham Mandeno
Guest
 
Posts: n/a
   
   
Re: Delete only specific field in record to Null

Hi Gina

It would REALLY help if you told us in what way it is not working - what
error is being raised (if any) and on what line of code, and if no error is
being raised then what is happening or not happening that is not as you
expect.

However, I can take a guess that the problem is with one or both of these
lines:

.Fields("AssignedTo") = "" 'Clear the person's name from the record
.Fields("DateAssigned").Value = "" 'Clear the Assign date

You are setting both these fields to an empty string. I assume DateAssigned
is a date/time field so you can't set it to a string (which is text).
Further, the AllowZeroLength property of the AssignedTo field is probably No
(the default) so you can't set it to an empty string either.

Usually when a field looks blank, its value is not an empty string, but
Null.

Try replacing both instances of /""/ above with /Null/ (without the slashes
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=11361
of course).

By the way, you called this "SQL script" but there is not an ounce of SQL in
it. It is actually VBA code (Visual Basic for Applications).

However, you might find that SQL is a better way to go. In your VBA code
you can construct a SQL command string to perform the update, and then
execute that SQL string.

The first step is to build a criteria string to identify which records to
update, then build a command string that looks like this:

Update Billing (fld1, fld2, fld3) values (val1, val2, val3) where ID in
(id1, id2, ...);

Try this:

Dim sSql as string, sIdList as String, vItem as variant
With Me!lstItems
For Each vItem in .ItemsSelected
sIdList = sIdList & .ItemData(vItem) & ","
Next vItem
End With
' we now have a string like this: "234, 345, 456,"
' remove the last comma
sIdList = Left(sIdList , Len(sIdList )-1)
' now add the rest of the SQL string
sSql = "Update Billing (Assigned, AssignedTo, DateAssigned) " _
& "values (0, Null, Null) where ID in ( " & sIdList & ");"
' now execute the SQL
CurrentDb.Execute sSql, dbFailOnError


--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

"Gina" wrote in message
news:0CD24052-8BF2-45FD-A569-3C1A1E23F0CE@microsoft.com...
> All,
>
> In the following SQL script I am trying to blank out the fields, but so
> far
> it isn't working. Can you point me in the right direction.
>
> Thanks!
>
> 'Setup the table and recordset to be edited
>
> ' strTablename = "Billing"
>
> Set db = CurrentDb
>
> Set rst = db.OpenRecordset(strTableName, dbOpenDynaset)
>
>
>
> For Each i In Me![lstItems].ItemsSelected 'Determine the number of
> items
> selected in the list
>
> Criteria = Me![lstItems].ItemData(i) 'Assign the Customer Number a
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=11361
> variable
>
>
>
> With rst
>
> .MoveFirst
>
> .FindFirst "[ID] = " & Criteria & "" 'Locate a Customer Number that
> matches the one selected from the list
>
> .Edit
>
> .Fields("Assigned") = 0 'Uncheck the checkbox
>
> .Fields("AssignedTo") = "" 'Clear the person's name from the record
>
> .Fields("DateAssigned").Value = "" 'Clear the Assign date
>
> .Update
>
> End With
>
> rst.Close
>
> Next i 'Loop through the next record
>
> Set db = Nothing 'Unset the Database
>
> Set rst = Nothing 'Unset the recordset
>
>
>
> Me.lstItems.Requery
>
> Exit Sub
>
>
> --
> Gina



Reply With Quote
  #4 (permalink)  
Old 28-Jul-2006, 08:20 AM
Ken Sheridan's Avatar Ken Sheridan
Guest
 
Posts: n/a
   
   
RE: Delete only specific field in record to Null

Gina:

Fields of date/Time data type can only be a valid date/time value or Null,
not a zero length string so try making it Null:

.Fields("DateAssigned") = Null 'Clear the Assign date

I would suggest that you do the same with the AssignedTo field too rather
than setting its value to a zero-length string, unless it's Required property
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=11361
is True in the table design. Also, rather than setting the value of the
Boolean (Yes/No) Assigned field to 0, set it to False:

.Fields("Assigned") = False 'Uncheck the checkbox

It will work in the same way, but its not considered good programming
practice to rely on the implementation, in this case of Boolean values as 0
or -1, but instead to use the Boolean False and True constants.

Ken Sheridan
Stafford, England

"Gina" wrote:

> Sorry, only the date field doesn't work.
> --
> Gina
>
>
> "Gina" wrote:
>
> > All,
> >
> > In the following SQL script I am trying to blank out the fields, but so far
> > it isn't working. Can you point me in the right direction.
> >
> > Thanks!
> >
> > 'Setup the table and recordset to be edited
> >
> > ' strTablename = "Billing"
> >
> > Set db = CurrentDb
> >
> > Set rst = db.OpenRecordset(strTableName, dbOpenDynaset)
> >
> >
> >
> > For Each i In Me![lstItems].ItemsSelected 'Determine the number of items
> > selected in the list
> >
> > Criteria = Me![lstItems].ItemData(i) 'Assign the Customer Number a
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=11361
> > variable
> >
> >
> >
> > With rst
> >
> > .MoveFirst
> >
> > .FindFirst "[ID] = " & Criteria & "" 'Locate a Customer Number that
> > matches the one selected from the list
> >
> > .Edit
> >
> > .Fields("Assigned") = 0 'Uncheck the checkbox
> >
> > .Fields("AssignedTo") = "" 'Clear the person's name from the record
> >
> > .Fields("DateAssigned").Value = "" 'Clear the Assign date
> >
> > .Update
> >
> > End With
> >
> > rst.Close
> >
> > Next i 'Loop through the next record
> >
> > Set db = Nothing 'Unset the Database
> >
> > Set rst = Nothing 'Unset the recordset
> >
> >
> >
> > Me.lstItems.Requery
> >
> > Exit Sub
> >
> >
> > --
> > Gina


Reply With Quote
  #5 (permalink)  
Old 28-Jul-2006, 08:20 AM
Gina's Avatar Gina
Guest
 
Posts: n/a
   
   
Re: Delete only specific field in record to Null

  Donate Today!  
It worked.

Thanks to both of you.

I apologize for sounding uninformed, for that is what it was. I was
submitting this for a co-worker. I also suggested the 'null' value, however,
it sometimes takes the experts like yourselves to say it.

As for SQL vs. VBA, You're right, he only writes VBA, I'm used to working
with SQL - so out of habit I stated that.

Again, thanks for your expert support as always.
--
Gina


"Graham Mandeno" wrote:

> Hi Gina
>
> It would REALLY help if you told us in what way it is not working - what
> error is being raised (if any) and on what line of code, and if no error is
> being raised then what is happening or not happening that is not as you
> expect.
>
> However, I can take a guess that the problem is with one or both of these
> lines:
>
> .Fields("AssignedTo") = "" 'Clear the person's name from the record
> .Fields("DateAssigned").Value = "" 'Clear the Assign date
>
> You are setting both these fields to an empty string. I assume DateAssigned
> is a date/time field so you can't set it to a string (which is text).
> Further, the AllowZeroLength property of the AssignedTo field is probably No
> (the default) so you can't set it to an empty string either.
>
> Usually when a field looks blank, its value is not an empty string, but
> Null.
>
> Try replacing both instances of /""/ above with /Null/ (without the slashes
> of course).
>
> By the way, you called this "SQL script" but there is not an ounce of SQL in
> it. It is actually VBA code (Visual Basic for Applications).
>
> However, you might find that SQL is a better way to go. In your VBA code
> you can construct a SQL command string to perform the update, and then
> execute that SQL string.
>
> The first step is to build a criteria string to identify which records to
> update, then build a command string that looks like this:
>
> Update Billing (fld1, fld2, fld3) values (val1, val2, val3) where ID in
> (id1, id2, ...);
>
> Try this:
>
> Dim sSql as string, sIdList as String, vItem as variant
> With Me!lstItems
> For Each vItem in .ItemsSelected
> sIdList = sIdList & .ItemData(vItem) & ","
> Next vItem
> End With
> ' we now have a string like this: "234, 345, 456,"
> ' remove the last comma
> sIdList = Left(sIdList , Len(sIdList )-1)
> ' now add the rest of the SQL string
> sSql = "Update Billing (Assigned, AssignedTo, DateAssigned) " _
> & "values (0, Null, Null) where ID in ( " & sIdList & ");"
> ' now execute the SQL
> CurrentDb.Execute sSql, dbFailOnError
>
>
> --
> Good Luck!
>
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=11361
> Graham Mandeno [Access MVP]
> Auckland, New Zealand
>
> "Gina" wrote in message
> news:0CD24052-8BF2-45FD-A569-3C1A1E23F0CE@microsoft.com...
> > All,
> >
> > In the following SQL script I am trying to blank out the fields, but so
> > far
> > it isn't working. Can you point me in the right direction.
> >
> > Thanks!
> >
> > 'Setup the table and recordset to be edited
> >
> > ' strTablename = "Billing"
> >
> > Set db = CurrentDb
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=11361
> >
> > Set rst = db.OpenRecordset(strTableName, dbOpenDynaset)
> >
> >
> >
> > For Each i In Me![lstItems].ItemsSelected 'Determine the number of
> > items
> > selected in the list
> >
> > Criteria = Me![lstItems].ItemData(i) 'Assign the Customer Number a
> > variable
> >
> >
> >
> > With rst
> >
> > .MoveFirst
> >
> > .FindFirst "[ID] = " & Criteria & "" 'Locate a Customer Number that
> > matches the one selected from the list
> >
> > .Edit
> >
> > .Fields("Assigned") = 0 'Uncheck the checkbox
> >
> > .Fields("AssignedTo") = "" 'Clear the person's name from the record
> >
> > .Fields("DateAssigned").Value = "" 'Clear the Assign date
> >
> > .Update
> >
> > End With
> >
> > rst.Close
> >
> > Next i 'Loop through the next record
> >
> > Set db = Nothing 'Unset the Database
> >
> > Set rst = Nothing 'Unset the recordset
> >
> >
> >
> > Me.lstItems.Requery
> >
> > Exit Sub
> >
> >
> > --
> > Gina

>
>
>

Reply With Quote
   Click Here to Donate Now!

Support Us!
Become a Promoter!
Gurfateh ji, you can become a SPN Promoter by Donating as little as $10 each month. With limited resources & high operational costs, your donations make it possible for us to deliver a quality website and spread the teachings of the Sri Guru Granth Sahib Ji, to serve & uplift humanity. Every contribution counts. Donate Generously. Gurfateh!
ReplyPost New Topic In This Forum Stay Connected to Sikhism, Click Here to Register Now!

Bookmarks


(View-All Members who have read this thread : 0
There are no names to display.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Tools Search
Search:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On

» Gurbani Jukebox
Listen to Gurbani while surfing SPN!
» Active Discussions
sikhism Who is "Mohan"?
Today 06:52 AM
21 Replies, 319 Views
sikhism need urgent advice.......
Today 06:46 AM
6 Replies, 72 Views
sikhism ਨਾਮਾ
Today 06:37 AM
2 Replies, 45 Views
sikhism Sikh Diamonds Video...
Today 04:23 AM
6 Replies, 112 Views
sikhism Are Creator and Creation...
Today 01:30 AM
44 Replies, 2,833 Views
sikhism Herman Hesse,...
Today 00:54 AM
13 Replies, 225 Views
sikhism On a Scale of Most...
Yesterday 21:42 PM
30 Replies, 1,277 Views
sikhism I became victim by...
Yesterday 19:50 PM
0 Replies, 39 Views
sikhism How important is Matha...
By Ishna
Yesterday 19:05 PM
58 Replies, 1,026 Views
sikhism Sikh Books downloads
Yesterday 15:39 PM
2 Replies, 62 Views
sikhism Salok Sheikh Farid ji...
Yesterday 09:35 AM
0 Replies, 43 Views
sikhism In Punjab, three farmers...
Yesterday 05:36 AM
0 Replies, 45 Views
sikhism Supernatural Sikhs, what...
Yesterday 03:45 AM
19 Replies, 408 Views
sikhism Sukhmani Sahib Astpadi...
26-May-2012 22:57 PM
0 Replies, 46 Views
Do You Think You Are...
26-May-2012 09:59 AM
94 Replies, 8,258 Views
» Books You Should Read...
Powered by vBadvanced CMPS v3.2.2

All times are GMT +6.5. The time now is 07:23 AM.
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.5.2 Copyright © 2004-12, All Rights Reserved. Sikh Philosophy Network


Page generated in 0.51415 seconds with 30 queries