Refresh Parent Form After Closing SubForm (1 Viewer)

HolmesSPH

New member
Local time
Today, 15:49
Joined
Jun 2, 2008
Messages
6
Hey everyone, I have been searching for days and testing millions of lines of code it feels like lol.

Here's the deal, I calling a sub form from a parent form. The sub form is editing data that the parent form also has access too.

So when I close the sub form I would like it to trigger a requery and refresh on the parent form... Any know have advice or know how to perform this?

Thanks in Advance!
Joshua
 

boblarson

Smeghead
Local time
Today, 12:49
Joined
Jan 12, 2001
Messages
32,059
You would just use:

Forms!YourForm1Name.Requery
 

missinglinq

AWF VIP
Local time
Today, 15:49
Joined
Jun 20, 2003
Messages
6,423
Your post is somewhat confusing. You don't "call" a subform from a main form; the subform is part of the main form, actually loads before the main form, and is always present. If what you really mean is that you're opening a second form, editing the data, then closing it and returning to your original form, you can do it like this:

In the code for the button (or whatever event you're using to open the second form)

Open the second form as popup/modal.
Edit your data, then
Use the line Me.Requery

By opening the second form as Modal, you'll halt the execution of the Me.Requery line until the second form is closed.

Good luck!
 

HolmesSPH

New member
Local time
Today, 15:49
Joined
Jun 2, 2008
Messages
6
I apologize if I am mixing terms, I am a web developer, lol and I hate VBA and Access...especially access 2000!

The form is being opened using DoCmd.OpenForm, I assumed that classifies is as a subform, let me know if I am wrong.

Secondly, the form being opened, is being populates from the form which called it. Soo..

Step 1 - Form loads with data

Step 2 - User clicks "Edit XXX" which calls DoCmd.OpenForm object method

Step 3 - Form loads

Step 4 - In the same function that calls DmCmd.OpenForm I send two pieces of data to the newly opened form (two text boxes)


Step 5 - User clicks "Submit Changes" and changes are saved

Step 6 - User closes form, thus the form which it was opened from, needs to requery and refresh to pick up the changes just made.

Step 6 is the step where things get kinked up..

If I use Forms!NameOfForm.Requery it tells me that form doesn't exist lol?!?

I've tried getting a form object:

Dim objForm as Form
Set objForm = Forms(Me.Parent.Name)

objForm.Requery
objForm.Refresh

this doesn't work either, let me know if there is anythign else that I didn't explain well, I hope this helps :)
 

boblarson

Smeghead
Local time
Today, 12:49
Joined
Jan 12, 2001
Messages
32,059
What is the name of the main form you want to requery. You say

Forms!NameOfForm.Requery

didn't work, but are you sure you chose the correct form name?
 

HolmesSPH

New member
Local time
Today, 15:49
Joined
Jun 2, 2008
Messages
6
I apologize I miss-spoke, the error I am getting is ...


Run-time error '2478':
Microsoft Access Doesn't allow you to use this method i the current view
 

boblarson

Smeghead
Local time
Today, 12:49
Joined
Jan 12, 2001
Messages
32,059
What event are you trying to put the code on?
 

HolmesSPH

New member
Local time
Today, 15:49
Joined
Jun 2, 2008
Messages
6
Well the Forms!NameOfForm.Refresh (or requery) is being called from a button click event on the sub form
 

HolmesSPH

New member
Local time
Today, 15:49
Joined
Jun 2, 2008
Messages
6
Sadly, I cannot, it won't operate either outside of it's current state, it's a linked database used by our Customer Service Reps to SQL Server.

I will however post you precisely the code.

Parent Form "Edit CreditCard Button": (Form Name WebOrders2)

Private Sub btnEditCreditCard_Click()
' Open the Edit Credit Card Form
DoCmd.OpenForm "EditCreditCard", , , , , acDialog
Forms!EditCreditCcard.Modal = True

' Populate the EditCreditCard Form with data
Forms("EditCreditCard").txtCreditCardNumber = DecryptCC(CreditCardNumber)
Forms("EditCreditCard").txtOrderId = OrderID
End Sub

Form Close Event in Modal Form Being Opened by Parent: (Form name EditCreditCard)
Private Sub Form_Close()
' I moved the Refresh/Requery code to the close form event
Forms!WebOrders2.Requery
Forms!WebOrders2.Refresh
End Sub




End Sub
 

HolmesSPH

New member
Local time
Today, 15:49
Joined
Jun 2, 2008
Messages
6
Alright well I figured out what the problem is...besides the fact that I am a moron..

I've been programming for almost 8 years, almost none of it has been VBA/Access, yes this Access 2000 app has humbled me lol...

Problem, I was refreshing the wrong Form... someone shoot me now..

Thanks for you help though, I really appreciate it!
 

boblarson

Smeghead
Local time
Today, 12:49
Joined
Jan 12, 2001
Messages
32,059
Alright well I figured out what the problem is...besides the fact that I am a moron..

I've been programming for almost 8 years, almost none of it has been VBA/Access, yes this Access 2000 app has humbled me lol...

Problem, I was refreshing the wrong Form... someone shoot me now..

Thanks for you help though, I really appreciate it!

Glad to hear you got it finally. Yes, I've been there before, so don't feel bad. It happens. :)


 

Users who are viewing this thread

Top Bottom