Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Global form refresh or requery function?

Status
Not open for further replies.

Kenny2003

Technical User
Dec 29, 2002
53
GB
Hi,

I am trying to write a global or multi-purpose function that will refresh or requery (what ever the correct term is) a form to reflect the updated record. The form contains normal data and has one field that displays a jpeg image (saved outside of the db as a link). I have various event procedures that happen when a form is opened or a record selected depending if a jpeg has been associated with a record or not.

If the record does have a jpeg then certain fields are displayed and others hidden.

If the record does *not* have an associated jpeg then certain other fields are displayed and others hidden.

I have a cmd button that calls a set of functions (developed by Candace Tripp) that allows a user to select a new image to add to the record.

It is at this point that I would like to call the form refresh or requery function, so that the newly added jpeg would trip the hide/display criteria that changes the fields displayed.

I have tried various methods and event commands and none seem to work.

I have written a module but when I add a new image and the fuction is called, Access gives me an "Object does not support this property or method" error. I have included my function code below. At the moment the function is called at the end of the command button's "on click" event.

Any suggestions would be great as I am totally stumped.

My grateful thanks in advance

Kenny

--------------------------Code begins-------------------
Option Compare Database


Function RequeryFrm()

If Trim(Nz(txtPicture, "")) = "" Then
[Forms]![frmPlant_Main].[Form]![Garden_Sub].Image1.Visible = False
[Forms]![frmPlant_Main].[Form]![Garden_Sub].txtPicture.Visible = True
[Forms]![frmPlant_Main].[Form]![Garden_Sub].cmdBrowse.Visible = True

Else
[Forms]![frmPlant_Main].[Form]![Garden_Sub].Image1.Visible = True
[Forms]![frmPlant_Main].[Form]![Garden_Sub].txtPicture.Visible = False
[Forms]![frmPlant_Main].[Form]![Garden_Sub].cmdBrowse.Visible = False

End If
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

RequeryFrm_Exit:
Exit Function

RequeryFrm_Err:
MsgBox Error$
Resume RequeryFrm_Exit

End Function
 
How are ya Kenny2003 . . . . .

What you really want to do is [blue]save the current record[/blue] (read about [purple]Refresh & Requery[/purple] in VBE help and find out exactly what they do).
Code:
[blue]   DoCmd.Save acForm, "FormName"
[purple]or:[/purple]
   DoCmd.RunCommand acCmdSaveRecord[/blue]

Calvin.gif
See Ya! . . . . . .
 
AceMan, I have to argue with you a little. [sad] I don't believe the Save method will save the record; rather, it saves the designated (or default) object - in this case, the form itself. To be certain, I tested it by putting a command button on a bound form and then tried both the Save and RunCommand methods. The Save method left the record dirty and allowed an <Esc> to undo the edits. The RunCommand method worked correctly.

Ken S.
 
Howdy Eupher! . . . . .

I put that in there just to see if you were alert! ;-)

[blue]Kenny2003[/blue] Disregard [blue]DoCmd.Save[/blue]



Calvin.gif
See Ya! . . . . . .
 
WOW - hey guys it worked a treat.

I used the DoCmd.RunCommand acCmdSaveRecord method and it does everything I wanted.

Thank you so so much.

Kenny
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top