Full Version: Refresh form
UtterAccess Forums > Microsoft® Access > Access Forms
tshudt
I am trying to regresh a form that is open when closing another form. I don't want to requery because I want the form to stay on the current record. I am having trouble writing the code and I am not having any luck searching UA on this topic, any help would be greatly appreciated.
Thank you
Tim
iandouglas
Am I being too simplistic in thinking putting
e.Refresh
In your forms On Current or On Got Focus event should do the trick?
Jack Cowley
If you have a variable that has the ID of the current record then code (created by 'schroep') like this in the event that closes the other form should work:
oCmd.OpenForm "frmCustomers"
[Forms]![frmCustomers].Requery
DoEvents
With Forms!frmCustomers
.RecordsetClone.FindFirst "[CustomerID] = " & varWithCustomerID
If Not .RecordsetClone.NoMatch Then .Bookmark = .RecordsetClone.Bookmark
End With
Change object names as necessary and this code has not be extensively tested so no guarantees.... The OpenForm code is OK even though the form is already open...
hth,
Jack
tshudt
Hi Jack Thanks for your response i get a sysntex error (missing operator) on this line
RecordsetClone.FindFirst "[webcourseID] = " & varWithwebcourseID
The form starts to requery and then stops on the first record
Each form has the same id
Thanks
Tim
Jack Cowley
Tim -
o you have the dot in front of RecorsetClone - .RecorsetClone.FindFirst "[WebcourseID] = " & varWithwebcourseID
Is WebcourseID as Number or Text? The code assumes a number. Have you stepped through your code to check the value in varWithwebcourseID to be sure it is what you expect it to be? Is WebcourseID the Primary Key?
Jack
tshudt
Yes Jack I have the dot. I have stepped through the code and it says the Variant is empty. Yes WebcourseID is the primary Key and is a number. Sorry for the trouble.
Thanks Tim
Jack Cowley
Tim -
o trouble at all. Now you know what the problem is! Good luck...
Jack
tshudt
I still have the problem the dot was there to begin with.
Jack Cowley
Oops, I thought you had found the problem... You say the variable is empty and if that is the case then that is probably the problem. How are you setting the variable? Where is the variable declared? Did you try your code using a known number to see if it worked and that the variable is the problem? Something like:
RecorsetClone.FindFirst "[WebcourseID] = 17"
Oused 17 but any number that is a 'good' WebcourseID will let you know if the variable is the problem.
Jack
tshudt
Hi Jack sorry for all the trouble, I did not declare the variables, I am not sure how. I did try and hard code the number of a record and the code ran but did not requery the data as expected. I think my best solution is to just put a button on my form and refresh it manualy.
im
Jack Cowley
Tim -
I am glad to help!
Open a new Standard module if you do not have a module already in the database. At the top of the code page you will see 'Option Compare Database' and below that you should see Option Explicit'. If you do not see Option Explicit then type it in. Below that type:
Public varWebcourseID as Long
Close and save the module as Module1, which will be the name suggested by Access, unless you add this to an existing module.
I will assume that you have a form open and it is on the WebcourseID that you want to return to. In the code in the button that opens the next form:
varWebcourseID = Me.NameOfControlOnFormWithWebcourseID
That will put your current WebcourseID into the variable varWebcourseID. Now try your forms and see if that works. You know how to check to see if varWebcourseID has a value so you can check that just to be sure.
If your are creating a record in your second form and it is supposed to show on the form that you will be returning to then you code might look something like this:
DoCmd.RunCommand acCmdSaveRecord
[Forms]![NameOfFormGoesHere].Requery
DoCmd.OpenForm "NameOfFormGoesHere"
DoEvents
With Forms!NameOfFormGoesHere
.RecordsetClone.FindFirst "[WebcourseD] = " & varWebcourseID
If Not .RecordsetClone.NoMatch Then .Bookmark = .RecordsetClone.Bookmark
End With
Let me know how you do...
Jack
tshudt
Thanks Jack for all your help. I will give it a try as soon as I get a chance.
Happy New Years!
Tim
Jack Cowley
Tim -
You are welcome and good luck with this!
Happy New Year to you too!
Jack
Aquadevel
Jack,
ts <only the 1st day of the new year>, so 'try' and keep up!
<Ok, I AM joking> frown.gif
Aqua
Jack Cowley
Aqua -
So, you are not joking! You a poking fun at a harmless old man... Heh heh...
Jack
Aquadevel
Yea,
was....sorry.
Wasn't it Forrest Gump that said: "Can't we all just be friends?"
<~~ remembers the day that 'clay' was invented!
Aqua
Jack Cowley
Aqua -
It was Rodney King that said, "Can't we just get along?" Forrest Gump said, "People call me Forrest Gump." Now that is some staggeringly good writing!!!
Jack
Aquadevel
hey,
I'm 'trying'!!!!!!
frown.gif
Aqua
Jack Cowley
Aqua -
When you get to be my age you will revel in the ability to remember anything!
Jack
Aquadevel
Jack,
st woman told me, "never ask a person's age".
But since I think you posted you are 'near the ripe ole age of 71 , or will be in 2038.........LOL
I'll be craoked by then.
Aqua
Jack Cowley
Aqua -
On 2038 I will be 108 years old... WHOOOEEEE! What a ride....
Jack
Aquadevel
you 'ARE' an ole dood!!!....
ok, ok, I am/was joking.
Aqua
Jack Cowley
Aqua -
old ya!!!
Now I am off for the rest of the evening. Going to search the Yellow Pages for rafts....
Jack
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.