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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form refresh after new record added. 1

Status
Not open for further replies.

Hammondo

MIS
Jan 14, 2002
23
0
0
NL
FormA contains SubformA. SubformA based upon a query display a list of records in tableA.

On my main form I have a button which when pressed opens data entry FormB and adds a new record to TableA.

I would like SubformA to refresh when I close FormB, so that it shows the new addition to TableA.

Does anyone know how/where can I do this?

Cheers in advance,
 
Hi!

This is one solution, involving VBA.

Right click on your button (to open entry form), in the select the "event" tab, and click the "button with 3 dots" on the right side of "on click" event.

This will take you to the VBA environment, and your code should look something like this:

Private Sub Command6_Click()
On Error GoTo Err_Command6_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmSomeForm"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command6_Click:
Exit Sub
Err_Command6_Click:
MsgBox Err.Description
Resume Exit_Command6_Click
End Sub

Now, to achieve the refresh, do the following changes:

The DoCmd statement should get "acdialog", which halts
execution in your main form until dataentry is completed.

Add the me.requery command, which executes afterwards to
give the intended refreshing

DoCmd.OpenForm stDocName, , , stLinkCriteria, , acDialog
Me.Requery

HTH Roy-Vidar
 
Ok this should do what you want.

In form B you must have a reference that coincides with Form A(A link). in this example lets us REG1 so when form2 is open it keeps that on the screen or hidden.

In Form2 onclose function add the following.

docmd.close

Dim stLinkCriteria As String
stLinkCriteria = "[REG1]=" & Me![REG1]
DoCmd.Save acForm, "FormB"
Docmd.close
DoCmd.OpenForm "FormA ", , , stLinkCriteria

What this will do is reopen the record that you where working on with the updated information.

If you require both screens open at the same time and you just want to refresh FormA whilst still open your best bet is to refresh each field in the form to do this create an invisible button on form one and on close of form one set focus to the invisible button, on gotfocus of the button add:

for example
me.field1.refresh
me.field2.refresh
etc...
Now the only one you do not want to do this to is the key.
this way it still has a link to the data record and does not ens up dumping you back at the first record.

This is the around about way of doing it, someone may come up with a simpler method.

Hope this helps

Zero Anarchy

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top