473,769 Members | 5,862 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What's wrong with this code???

This is the set up:
[Text6] is a date field on a form. Its control source is
the field "date_enter ed" in"Table1". If there is a date showing
in the date_entered field (Text6) & the status in Combo box2
shows "deleted" then the after update event should delete the
date in Text6 & return the field "date_enter ed to a null value
when the form is closed. Even though the debug window shows
rst!date entered as null when you step through this event the
table still has the original value when you view it after the
form is closed.

Private Sub Form_AfterUpdat e()

If Me.Combo2.Colum n(0) <> "deleted" Then
Me.Text6.Enable d = True
Me.Text6 = ""
Dim db As Database
Dim rst As Recordset
Set db = CurrentDb()
Set rst = db.OpenRecordse t("table1", dbOpenTable)
rst.Edit
IsNull (rst!date_enter ed)
rst.Update
rst.close
Set db = Nothing
End If

End Sub

What am I missing???
I'm sure its something simple cause what am trying to do
is pretty basic but absolutely refuses to work in this form
Thanks for any guidance you can give me
dc
Mar 23 '06 #1
6 1416
On Thu, 23 Mar 2006 16:51:59 -0600, doncee
<no************ *****@charter.n et> wrote:
This is the set up:
[Text6] is a date field on a form. Its control source is
the field "date_enter ed" in"Table1". If there is a date showing
in the date_entered field (Text6) & the status in Combo box2
shows "deleted" then the after update event should delete the
date in Text6 & return the field "date_enter ed to a null value
when the form is closed. Even though the debug window shows
rst!date entered as null when you step through this event the
table still has the original value when you view it after the
form is closed.

Private Sub Form_AfterUpdat e()

If Me.Combo2.Colum n(0) <> "deleted" Then
Me.Text6.Enable d = True
Me.Text6 = ""
Dim db As Database
Dim rst As Recordset
Set db = CurrentDb()
Set rst = db.OpenRecordse t("table1", dbOpenTable)
rst.Edit
IsNull (rst!date_enter ed)
rst.Update
rst.close
Set db = Nothing
End If

End Sub

What am I missing???
I'm sure its something simple cause what am trying to do
is pretty basic but absolutely refuses to work in this form
Thanks for any guidance you can give me
dc


Should probably move this to the form's BeforerUpdate event.

I'm assuming you're trying to set the value of Text6 to NULL if the
combo is anything other than deleted? If so, try this:

If Me.Combo2.Colum n(0) <> "deleted" Then Me.Text6=Null

This assumes:
your combo is a single column combo
your form is bound to table1, or a query containing table1
Text6 is bound to date_entered

Mar 24 '06 #2
Bri

doncee wrote:
This is the set up:
[Text6] is a date field on a form. Its control source is
the field "date_enter ed" in"Table1". If there is a date showing
in the date_entered field (Text6) & the status in Combo box2
shows "deleted" then the after update event should delete the
date in Text6 & return the field "date_enter ed to a null value
when the form is closed. Even though the debug window shows
rst!date entered as null when you step through this event the
table still has the original value when you view it after the
form is closed.

Private Sub Form_AfterUpdat e()

If Me.Combo2.Colum n(0) <> "deleted" Then
Me.Text6.Enable d = True
Me.Text6 = ""
Dim db As Database
Dim rst As Recordset
Set db = CurrentDb()
Set rst = db.OpenRecordse t("table1", dbOpenTable)
rst.Edit
IsNull (rst!date_enter ed)
rst.Update
rst.close
Set db = Nothing
End If

End Sub

What am I missing???
I'm sure its something simple cause what am trying to do
is pretty basic but absolutely refuses to work in this form
Thanks for any guidance you can give me
dc


Since you asked what was wrong with you code, here goes. There are a few
things about this code that seem to be doing things the hard way. Lets
look at some of your lines of code:

If Me.Combo2.Colum n(0) <> "deleted" Then
- This does the opposite of what you state you want to do. The code in
the If Block will run if the value of Combo2 is NOT equal to deleted.
Also, there is no test for the value of date_entered.

Me.Text6.Enable d = True
- This is not necessary since the Enabled Property is only for the User
interface, the control value can be changed regardless via VBA.

Me.Text6 = ""
- If Text6 is bound to Table1.date_ent ered and date_entered is a
Date/Time field then you cannot set it to an empty string. You can set
it to Null as in:
Me.Text6 = Null

This makes the rest of the code superfluous, but lets look at it anyway:
Set rst = db.OpenRecordse t("table1", dbOpenTable)
rst.Edit
- You do not move to the current record before you do the edit, so it
will always be the first record of the table that is edited, not the
current record (unless the current record is the first record)

IsNull (rst!date_enter ed)
- This line does NOT change the value of rst!date_entere d, instead it
should be:
rst!date_entere d = Null

Since you are changing the value of a field in the current record, you
should run this in the BeforeUpdate event so the record doesn't have to
be saved twice. Also, you should never modify the value of a field via
the recordset that is also being changed via the control, this can cause
locking issues.

End result is that the code should be:
Private Sub Form_BeforeUpda te()
If Me.Combo2.Colum n(0) = "deleted" AND Len(Me.Text6 &"")>0 Then
Me.Text6 = Null
End If
End Sub

I hope that helps.

--
Bri

Mar 24 '06 #3
There is lots wrong with the code. See my comments inline.

doncee <no************ *****@charter.n et> wrote in
news:Xn******** *************** **@216.196.97.1 31:
This is the set up:
[Text6] is a date field on a form. Its control source
is
the field "date_enter ed" in"Table1". If there is a date
showing in the date_entered field (Text6) & the status in
Combo box2 shows "deleted" then the after update event should
delete the date in Text6 & return the field "date_enter ed to
a null value when the form is closed. Even though the debug
window shows rst!date entered as null when you step through
this event the table still has the original value when you
view it after the form is closed.

Private Sub Form_AfterUpdat e()

If Me.Combo2.Colum n(0) <> "deleted" Then
Me.Text6.Enable d = True
Me.Text6 = ""
Dim db As Database
Dim rst As Recordset
Set db = CurrentDb()
Set rst = db.OpenRecordse t("table1", dbOpenTable) ' you are on the first record of the table. yo need something to
' set the recordset to the appropriate record. rst.Edit
' Here you are testing whether your current record is null. You
'are not changing the value to null IsNull (rst!date_enter ed)
rst.Update
rst.close
Set db = Nothing
End If

End Sub
General comment, why go to all the trouble of opening a
recordset. All you need is to do is put
If Me.Combo2.Colum n(0) <> "deleted" Then
Me.text6 = null 'set the new value.
end if
in the form's BeforeUpdate event.
What am I missing???
I'm sure its something simple cause what am trying to do
is pretty basic but absolutely refuses to work in this form
Thanks for any guidance you can give me
dc


--
Bob Quintal

PA is y I've altered my email address.
Mar 24 '06 #4
Bob Quintal <rq******@sympa tico.ca> wrote in
news:Xn******** **************@ 207.35.177.135:
There is lots wrong with the code. See my comments inline.

doncee <no************ *****@charter.n et> wrote in
news:Xn******** *************** **@216.196.97.1 31:
This is the set up:
[Text6] is a date field on a form. Its control
source is
the field "date_enter ed" in"Table1". If there is a date
showing in the date_entered field (Text6) & the status in
Combo box2 shows "deleted" then the after update event
should delete the date in Text6 & return the field
"date_enter ed to a null value when the form is closed.
Even though the debug window shows rst!date entered as
null when you step through this event the table still has
the original value when you view it after the form is
closed.

Private Sub Form_AfterUpdat e()

If Me.Combo2.Colum n(0) <> "deleted" Then
Me.Text6.Enable d = True
Me.Text6 = ""
Dim db As Database
Dim rst As Recordset
Set db = CurrentDb()
Set rst = db.OpenRecordse t("table1", dbOpenTable)

' you are on the first record of the table. yo need
something to ' set the recordset to the appropriate record.
rst.Edit


' Here you are testing whether your current record is null.
You 'are not changing the value to null
IsNull (rst!date_enter ed)
rst.Update
rst.close
Set db = Nothing
End If

End Sub

General comment, why go to all the trouble of opening a
recordset. All you need is to do is put
If Me.Combo2.Colum n(0) <> "deleted" Then
Me.text6 = null 'set the new value.
end if
in the form's BeforeUpdate event.
What am I missing???
I'm sure its something simple cause what am trying to do
is pretty basic but absolutely refuses to work in this
form Thanks for any guidance you can give me
dc



Thanks a lot. Works like a charm.
You sure simplified it for me.
dc
Mar 24 '06 #5
Bri <no*@here.com > wrote in
news:T0HUf.1736 34$sa3.121722@p d7tw1no:

doncee wrote:
This is the set up:
[Text6] is a date field on a form. Its control
source is
the field "date_enter ed" in"Table1". If there is a date
showing in the date_entered field (Text6) & the status in
Combo box2 shows "deleted" then the after update event
should delete the date in Text6 & return the field
"date_enter ed to a null value when the form is closed.
Even though the debug window shows rst!date entered as
null when you step through this event the table still has
the original value when you view it after the form is
closed.

Private Sub Form_AfterUpdat e()

If Me.Combo2.Colum n(0) <> "deleted" Then
Me.Text6.Enable d = True
Me.Text6 = ""
Dim db As Database
Dim rst As Recordset
Set db = CurrentDb()
Set rst = db.OpenRecordse t("table1", dbOpenTable)
rst.Edit
IsNull (rst!date_enter ed)
rst.Update
rst.close
Set db = Nothing
End If

End Sub

What am I missing???
I'm sure its something simple cause what am trying to do
is pretty basic but absolutely refuses to work in this
form Thanks for any guidance you can give me
dc


Since you asked what was wrong with you code, here goes.
There are a few things about this code that seem to be
doing things the hard way. Lets look at some of your lines
of code:

If Me.Combo2.Colum n(0) <> "deleted" Then
- This does the opposite of what you state you want to do.
The code in the If Block will run if the value of Combo2 is
NOT equal to deleted. Also, there is no test for the value
of date_entered.

Me.Text6.Enable d = True
- This is not necessary since the Enabled Property is only
for the User interface, the control value can be changed
regardless via VBA.

Me.Text6 = ""
- If Text6 is bound to Table1.date_ent ered and date_entered
is a Date/Time field then you cannot set it to an empty
string. You can set it to Null as in:
Me.Text6 = Null

This makes the rest of the code superfluous, but lets look
at it anyway: Set rst = db.OpenRecordse t("table1",
dbOpenTable) rst.Edit
- You do not move to the current record before you do the
edit, so it will always be the first record of the table
that is edited, not the current record (unless the current
record is the first record)

IsNull (rst!date_enter ed)
- This line does NOT change the value of rst!date_entere d,
instead it should be:
rst!date_entere d = Null

Since you are changing the value of a field in the current
record, you should run this in the BeforeUpdate event so
the record doesn't have to be saved twice. Also, you should
never modify the value of a field via the recordset that is
also being changed via the control, this can cause locking
issues.

End result is that the code should be:
Private Sub Form_BeforeUpda te()
If Me.Combo2.Colum n(0) = "deleted" AND Len(Me.Text6
&"")>0 Then
Me.Text6 = Null
End If
End Sub

I hope that helps.

--
Bri


Your coding was what I needed.
Thanks for your help
dc
Mar 24 '06 #6
scott <scott@NoSpam_I nfotrakker.com> wrote in
news:gc******** *************** *********@4ax.c om:
On Thu, 23 Mar 2006 16:51:59 -0600, doncee
<no************ *****@charter.n et> wrote:
This is the set up:
[Text6] is a date field on a form. Its control
source is
the field "date_enter ed" in"Table1". If there is a date
showing in the date_entered field (Text6) & the status in
Combo box2 shows "deleted" then the after update event
should delete the date in Text6 & return the field
"date_enter ed to a null value when the form is closed.
Even though the debug window shows rst!date entered as null
when you step through this event the table still has the
original value when you view it after the form is closed.

Private Sub Form_AfterUpdat e()

If Me.Combo2.Colum n(0) <> "deleted" Then
Me.Text6.Enable d = True
Me.Text6 = ""
Dim db As Database
Dim rst As Recordset
Set db = CurrentDb()
Set rst = db.OpenRecordse t("table1", dbOpenTable)
rst.Edit
IsNull (rst!date_enter ed)
rst.Update
rst.close
Set db = Nothing
End If

End Sub

What am I missing???
I'm sure its something simple cause what am trying to do
is pretty basic but absolutely refuses to work in this form
Thanks for any guidance you can give me
dc


Should probably move this to the form's BeforerUpdate
event.

I'm assuming you're trying to set the value of Text6 to
NULL if the combo is anything other than deleted? If so,
try this:

If Me.Combo2.Colum n(0) <> "deleted" Then Me.Text6=Null

This assumes:
your combo is a single column combo
your form is bound to table1, or a query containing table1
Text6 is bound to date_entered


Thanks for your help. Just what I needed.
works great
dc
Mar 24 '06 #7

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

Similar topics

125
14841
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from software giant such as Microsoft SQL Server, Oracle, and Sybase? Is PostgreSQL reliable enough to be used for high-end commercial application? Thanks
72
5891
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for example, between a C/C++ programmers with a few weeks of experience and a C/C++ programmer with years of experience. You don't really need to understand the subtle details or use the obscure features of either language
121
10164
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode support IDEs are DreamWeaver 8 and Zend PHP Studio. DreamWeaver provides full support for Unicode. However, DreamWeaver is a web editor rather than a PHP IDE. It only supports basic IntelliSense (or code completion) and doesn't have anything...
51
13387
by: WindAndWaves | last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one of those NEVER USE. I can understand that it may lead to confusing code, but I often use it like this: is this wrong????? Function x select case z
46
4255
by: Keith K | last post by:
Having developed with VB since 1992, I am now VERY interested in C#. I've written several applications with C# and I do enjoy the language. What C# Needs: There are a few things that I do believe MSFT should do to improve C#, however. I know that in the "Whidbey" release of VS.NET currently
13
5058
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
1
1466
by: GS | last post by:
I got a combobox box that I load at load time. the Item and vales ended up in reverse order of each other, what went wrong? the database table has the following row code value ebay http://www.ebay.com google http://www.google.com yahoo http://www.yahoo.com However in the drop down list displayed value used ebay http://www.yahoo.com
98
4624
by: tjb | last post by:
I often see code like this: /// <summary> /// Removes a node. /// </summary> /// <param name="node">The node to remove.</param> public void RemoveNode(Node node) { <...> }
9
2123
by: Pyenos | last post by:
import cPickle, shelve could someone tell me what things are wrong with my code? class progress: PROGRESS_TABLE_ACTIONS= DEFAULT_PROGRESS_DATA_FILE="progress_data" PROGRESS_OUTCOMES=
20
2819
by: Daniel.C | last post by:
Hello. I just copied this code from my book with no modification : #include <stdio.h> /* count characters in input; 1st version */ main() { long nc; nc = 0;
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9416
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9979
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9849
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8861
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6661
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3948
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
2
3551
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.