UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Updating Date Field, Access 2013    
 
   
tbs
post Jun 12 2018, 10:30 AM
Post#1



Posts: 292
Joined: 12-February 13



I had this in my procedure and it worked fine. Now it doesn't without explanation:

CODE
Private Sub CmdClose_Click()
Do.Cmd.RunCommand acCmdRefresh
Do.Cmd.RunCommand acCmdSaveRecord
Me.DateEdit = Now()
DoCmd.Close


What I want to do is when pressed a button, the code fires away to save records on the form and log the dateedit field with today's date/time before closing the form.

I even tried to put:

CODE
Private Sub DateEdit_AfterUpdate()
Me.DateEdit = Now()
End Sub


In afterupdate property. It didn't work.

iconfused.gif
Go to the top of the page
 
GroverParkGeorge
post Jun 12 2018, 10:33 AM
Post#2


UA Admin
Posts: 33,463
Joined: 20-June 02
From: Newcastle, WA


Please clarify: what does it mean to say "it doesn't work". DO you get an error? Nothing happens? or??

--------------------
My Real Name Is George. Grover Park Consulting is where I do business.
How to Ask a Good Question
Beginning SQL Server
Visit My Blog on Facebook
Go to the top of the page
 
tbs
post Jun 12 2018, 10:52 AM
Post#3



Posts: 292
Joined: 12-February 13



I get a yellow highlight in VBA when I click on DEBUG.

(edit: after I get out of back to back meetings, I will add a error handling to see what code it says).
This post has been edited by tbs: Jun 12 2018, 10:57 AM
Go to the top of the page
 
GroverParkGeorge
post Jun 12 2018, 10:56 AM
Post#4


UA Admin
Posts: 33,463
Joined: 20-June 02
From: Newcastle, WA


And is there an error message with it? If so, what does that error message say?

Yellow highlights mean, or should mean, that you are stepping through the code and that line is the current line to be executed next, so I'm not sure it's a bug.

What happens if you press the F8 key while that line is highlighted?

--------------------
My Real Name Is George. Grover Park Consulting is where I do business.
How to Ask a Good Question
Beginning SQL Server
Visit My Blog on Facebook
Go to the top of the page
 
tbs
post Jun 12 2018, 11:01 AM
Post#5



Posts: 292
Joined: 12-February 13



I just hit F8 and it says "run time error -2147352567 (800200009): you cant assign a value to this object."

This happens on and off. I suspect it has something to do when I update other open forms (I have several open forms before I close the main form with this code).
Go to the top of the page
 
GroverParkGeorge
post Jun 12 2018, 12:12 PM
Post#6


UA Admin
Posts: 33,463
Joined: 20-June 02
From: Newcastle, WA


hm. We'd really have to see the entire procedure most likely. You have multiple forms open and code impacting one or more of them, apparently.

So, if you can upload a sample copy, with just enough data to see how it's suppose to work, it might be helpful.

--------------------
My Real Name Is George. Grover Park Consulting is where I do business.
How to Ask a Good Question
Beginning SQL Server
Visit My Blog on Facebook
Go to the top of the page
 
theDBguy
post Jun 12 2018, 12:47 PM
Post#7


Access Wiki and Forums Moderator
Posts: 73,203
Joined: 19-June 07
From: SunnySandyEggo


Hi,

Pardon me for jumping in... What is the Control Source for [DateEdit]? Is it a calculated, unbound Textbox?

Just curious...

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
stevep
post Jun 12 2018, 07:17 PM
Post#8



Posts: 71
Joined: 9-November 14



I see you have Do.Cmd, did you mean DoCmd?
Go to the top of the page
 
tbs
post Jun 13 2018, 07:36 AM
Post#9



Posts: 292
Joined: 12-February 13



Good morning.

I am going to try and work on this in between jobs.

I meant DoCmd so I had it correct.

Doc - the control source for [DateEdit] is the field itself (bounded textbox).

George - you are right about possibility of code impacting one or more of them. I believe the issue happens when I open a certain form that is not part of the multiple forms when initially opened. I will look into this first and provide an update by the end of the day. If I have no success, I will try and upload a sample copy.

Thanks for helping out...
Go to the top of the page
 
tbs
post Jun 13 2018, 11:41 AM
Post#10



Posts: 292
Joined: 12-February 13



I suspect the error is happening because other forms has a same field name [DateEdit].

Since the [DateEdit] is on "frmmainpage" I am thinking I should specify that. How do I do that? I thought maybe it should be something like this:

CODE
Me.form!frmmainpage.dateedit = now()


Go to the top of the page
 
tbs
post Jun 13 2018, 11:54 AM
Post#11



Posts: 292
Joined: 12-February 13



I even tried inserting

CODE
me.dateedit = now()


in the Property Sheet event (On Close) but it didn't work.

I even tried in the [DateEdit] textbox property sheet (On Exit).


Go to the top of the page
 
tbs
post Jun 13 2018, 01:16 PM
Post#12



Posts: 292
Joined: 12-February 13



Okay, here is a modified fix - I think and so far....

I found this link and build a macro.

Then here is the whole VBA (I added the runmacro line):

CODE
Private Sub CmdClose_Click()

    ' this code runs the macro to update dateedit field in the main page.
DoCmd.RunMacro "Last Modified"

'This code closes all open forms in the current project
Dim obj As Object
Dim strName As String
For Each obj In Application.CurrentProject.AllForms
DoCmd.Close acForm, obj.Name, acSaveYes

Next obj

    ' and then opens the named form in quotations

DoCmd.OpenForm "frmWelcome", acNormal, "", "", acEdit, acNormal

End Sub



I'm not sure if the "Next ojb" is necessary. I got this code from somewhere but did not make a note where I got it. frown.gif


Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    18th September 2018 - 02:40 PM