PC Review


Reply
Thread Tools Rate Thread

Delete record in VBA

 
 
=?Utf-8?B?aHVyc3R5?=
Guest
Posts: n/a
 
      22nd Jun 2006
I am making a defect tracking database and in one of the forms I want to keep
the date after they hit submit so that the person entering data doesn't have
to type in the date everytime. The text box is called EntryDate
So, to solve that problem I did one of these...

Private Sub Submit2_Click()
On Error GoTo Err_Submit2_Click
Dim savedate As Date
savedate = EntryDate
DoCmd.GoToRecord , , acNewRec
Me.EntryDate.SetFocus
Me.EntryDate = savedate
Exit_Submit2_Click:
Exit Sub

Err_Submit2_Click:
MsgBox Err.Description
Resume Exit_Submit2_Click
End Sub

I added the

Dim savedate As Date
savedate = EntryDate

Me.EntryDate = savedate

to the code so it would save the date.
This part of it works fine, however, now I have a new problem.
After submitting the last record, and hitting the 'X' to close, I get the
following error.
"The field 'Recrate Reason Table.Reason Code' cannot contain a Null Value
because the Required property for this field is set to True. Enter a value in
this field"
I still want Reason Code to be required for all the entries but I don't want
this message to pop up everytime.
So I tried to figure out some sort of delete record command on Form_close
but it was to no avail.
Please Help
 
Reply With Quote
 
 
 
 
Allen Browne
Guest
Posts: n/a
 
      22nd Jun 2006
If you just want to store the date that the record was entered or last
modified, just use the BeforeUpdate event of the *form*:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.EntryDate = Date
End Sub

This event fires just before Access saves the record. You can then omit your
Submit2 button, or else just use it it save the record:
RunCommand acCmdSaveRecord

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"hursty" <(E-Mail Removed)> wrote in message
news:19E992AD-3A11-4786-827E-(E-Mail Removed)...
>I am making a defect tracking database and in one of the forms I want to
>keep
> the date after they hit submit so that the person entering data doesn't
> have
> to type in the date everytime. The text box is called EntryDate
> So, to solve that problem I did one of these...
>
> Private Sub Submit2_Click()
> On Error GoTo Err_Submit2_Click
> Dim savedate As Date
> savedate = EntryDate
> DoCmd.GoToRecord , , acNewRec
> Me.EntryDate.SetFocus
> Me.EntryDate = savedate
> Exit_Submit2_Click:
> Exit Sub
>
> Err_Submit2_Click:
> MsgBox Err.Description
> Resume Exit_Submit2_Click
> End Sub
>
> I added the
>
> Dim savedate As Date
> savedate = EntryDate
>
> Me.EntryDate = savedate
>
> to the code so it would save the date.
> This part of it works fine, however, now I have a new problem.
> After submitting the last record, and hitting the 'X' to close, I get the
> following error.
> "The field 'Recrate Reason Table.Reason Code' cannot contain a Null Value
> because the Required property for this field is set to True. Enter a value
> in
> this field"
> I still want Reason Code to be required for all the entries but I don't
> want
> this message to pop up everytime.
> So I tried to figure out some sort of delete record command on Form_close
> but it was to no avail.
> Please Help



 
Reply With Quote
 
=?Utf-8?B?aHVyc3R5?=
Guest
Posts: n/a
 
      22nd Jun 2006

I want the person entering data to be able to put in records from other
dates, not just today's date.

"Allen Browne" wrote:

> If you just want to store the date that the record was entered or last
> modified, just use the BeforeUpdate event of the *form*:
> Private Sub Form_BeforeUpdate(Cancel As Integer)
> Me.EntryDate = Date
> End Sub
>
> This event fires just before Access saves the record. You can then omit your
> Submit2 button, or else just use it it save the record:
> RunCommand acCmdSaveRecord
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia.
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>

 
Reply With Quote
 
Allen Browne
Guest
Posts: n/a
 
      23rd Jun 2006
Perhaps move the code into the form's BeforeInsert event then?

Or just set the Default Value of that text box to:
=Date()

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"hursty" <(E-Mail Removed)> wrote in message
news:885DFBA3-34F9-46E2-AA86-(E-Mail Removed)...
>
> I want the person entering data to be able to put in records from other
> dates, not just today's date.
>
> "Allen Browne" wrote:
>
>> If you just want to store the date that the record was entered or last
>> modified, just use the BeforeUpdate event of the *form*:
>> Private Sub Form_BeforeUpdate(Cancel As Integer)
>> Me.EntryDate = Date
>> End Sub
>>
>> This event fires just before Access saves the record. You can then omit
>> your
>> Submit2 button, or else just use it it save the record:
>> RunCommand acCmdSaveRecord



 
Reply With Quote
 
=?Utf-8?B?aHVyc3R5?=
Guest
Posts: n/a
 
      23rd Jun 2006
Setting the default value to date doesn't solve my problem. I already have
the previously entered date as the default. But, when you have just entered
to record, hit submit, the form clears and the date just entered will pop up
again. That is what I want to happen. But then when you try to close the
form with only the date box filled out it gives me that error about required
fields. I have the date doing what I want it to do unless there is a better
way to do it, but it is in closing the form with a partially filled out
record that is my problem.

 
Reply With Quote
 
Allen Browne
Guest
Posts: n/a
 
      23rd Jun 2006
Did you try moving the code into Form_BeforeUpdate, so you are not dirtying
the form too early?

AFAICT, the problem seems to arise from the fact that you are assigning a
value to a bound control before it is warranted.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"hursty" <(E-Mail Removed)> wrote in message
news:088093B7-CA7E-438D-8F67-(E-Mail Removed)...
> Setting the default value to date doesn't solve my problem. I already
> have
> the previously entered date as the default. But, when you have just
> entered
> to record, hit submit, the form clears and the date just entered will pop
> up
> again. That is what I want to happen. But then when you try to close the
> form with only the date box filled out it gives me that error about
> required
> fields. I have the date doing what I want it to do unless there is a
> better
> way to do it, but it is in closing the form with a partially filled out
> record that is my problem.
>



 
Reply With Quote
 
=?Utf-8?B?aHVyc3R5?=
Guest
Posts: n/a
 
      23rd Jun 2006
Yes, I did try that, but that was only if I wanted it to be today's date. I
don't want to always enter today's date. I think I'm am going to forget it.

"Allen Browne" wrote:

> Did you try moving the code into Form_BeforeUpdate, so you are not dirtying
> the form too early?
>
> AFAICT, the problem seems to arise from the fact that you are assigning a
> value to a bound control before it is warranted.
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia.
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Prevent Subform from saving record or delete record when moving tomain form RussCRM Microsoft Access Form Coding 0 3rd Apr 2008 07:26 PM
Re: Add / Delete record from table - How to reposition selected record in datagridview??? Cor Ligthert[MVP] Microsoft VB .NET 0 31st Mar 2008 05:26 AM
How to delete a SQL Server record (descending from another record of the same table) with a C# application polocar Microsoft C# .NET 6 23rd Jul 2006 03:20 AM
Upon delete record, conditional delete record from another table =?Utf-8?B?UmljaDEyMzQ=?= Microsoft Access 6 14th Oct 2005 02:48 PM
Delete Button shows previous record before current record is delet =?Utf-8?B?UmljaDEyMzQ=?= Microsoft Access Forms 8 10th Oct 2005 01:15 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:17 AM.