|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
January 21st, 2005, 08:54 PM
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Need help to refresh two forms
Hi there,
I have two forms: form_A and form_B. When I double click a field(named:hours)in form_A, it should pop up the form_B and ask user to enter some information in form_B.
My problem are as follows:
1.When I re-open the form_B, the data I entered before still stick there. I hope the form_B is a blank form withou any data in it.
2.After I enter the data in form_B and close it, I could not see any
data in the field "hour" of form_A; if I re-open the form_B and close it again, the data is displayed in the field "hour" of form_A. I tried to refresh form_A as form_B is closed, but that doesn't work.
Thanks in advance!
flyfish
__________________
flyfish
|
January 22nd, 2005, 12:24 AM
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
In the After Insert of the Main Form you need to issue a Requery on the second subform Forms!FormName!SubFormControlName.Form.Requery
Jaime E. Maccou
|
January 22nd, 2005, 05:52 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
Hi flyfish,
If I'm reading you correctly, you're not using a subform, but rather a popup style data entry dialog form. If that's the case, place the following in FormA's textbox double click event:
Private Sub txtHours_DblClick(Cancel As Integer)
DoCmd.OpenForm "FormB", , , , DataMode:=acFormAdd, WindowMode:=acDialog
DoCmd.GoToRecord acDataForm, Me.Name, acLast
End Sub
The DataMode argument will ensure that FormB opens to a new (blank) record, and the WindowMode argument sets FormB's Modal and Popup properties to true (standard settings for a dialog style form). You can also set FormB's BorderStyle property to Dialog if you like. The second line of code will advance FormA to the last record added by closing FormB (acLast).
In the click event of the command button you use to close form B, place the following:
Private Sub cmdSave_Click()
'Validate that txtHours IsNotNull before saving records.
If IsNull(Me!txtHours) Then
MsgBox "Please enter hour information before saving record.", , "Can't save record"
Me!txtHours.SetFocus
Else
'Save Record.
DoCmd.RunCommand acCmdSaveRecord
End If
'Requery (rather than Refresh) FormA's Record Source
Forms!FormA.Requery
'Close FormB
DoCmd.Close acForm, Me.Name
End Sub
The code assumes that you are using bound forms, and that FormB's records soucre (say a table) is included in FormA's record source (say a query based on FormB's records sorce table and possibly other tables.)
HTH,
Bob
|
January 23rd, 2005, 08:30 PM
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi, there,
Thanks so much for your replies!
Bob, I tried to add the following codes into the formA's textbox on click event:
DoCmd.OpenForm "work_hours_dialog", , , , DataMode:=acFormAdd, WindowMode:=acDialog
DoCmd.GoToRecord acDataForm, Me.Name, acLast
But I got an error message(runtime error 2489) that reminds me the object formA isn't opened.
Also, I am not very clear about the definition of bound form, could you explain it to me? Thanks!
flyfish
|
January 24th, 2005, 10:26 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
Bound forms and bound controls are simply forms and controls that have their RecordSource and ControlSource properties set at either design or runtime. This is Access's default method of doing business. All bound forms in an .mdb file are bound to a behind-the-scenes DAO recordset which the Jet database engine uses to manage all your record navigation and CRUD (Create, Retrieve, Update, Delete) operations as you click Access interface controls or issue DoCmd commands. You are using bound forms.
formA has to be open if you are able to click its textbox. Do you mean formB? Be sure it exists also. The last line of code:
DoCmd.GoToRecord acDataForm, Me.Name, acLast
isn't intended to execute until after formB has been opened and closed, and control returns to formA's double-click event.
HTH,
Bob
|
January 24th, 2005, 02:06 PM
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Bob,
Can I email my code to you? Thanks!
flyfish
|
January 24th, 2005, 02:24 PM
|
Authorized User
|
|
Join Date: Jan 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I have used this before to update a combo box once a new entry was added. It refreshs the form.
Form A - Load Event
'Refresh the form everytime it is loaded
Private Sub Form_Load(Cancel As Integer)
DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
End Sub
Then in form B - Open Event
'Takes you to a new record when the form is opend
Private Sub Form_Load()
DoCmd.GoToRecord , , acNewRec
End Sub
Then a button to take you back to form A from form B.
Hope the helps
Matt
|
January 24th, 2005, 03:57 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
Apologies flyfish, but I prefer to confine discussions to the forum.
- Bob
|
January 24th, 2005, 09:24 PM
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I tried all suggestions, but still doesn't work. Maybe I didn't explain the question clearly.
form_A is a sub-form of MainForm, connected to mainform by ID.
The purpose of this page is to ask workers to enter the hours they spend on each project.
In the sub-form "form-A", When a user double click the field "hours_date", there is a datasheet(form_B) pop up and ask the user to enter the detailed information about the hours they spent on the project. When the form_B is closed, sum of the hours from the form_B will be displayed in the "hours_date" field of form_A.
My problem is when I double click the field "hours_date" in the form_A, enter the hours distribution in the datasheet(form_B)and close form_B. I couldn't find the corresponding data in form_A;If I
double click the field in form-A again, then close the datasheet(because the old data still sticked on the datasheet). I see the
correct result in the form-A. I want form_B is blank everytime when it open; I only need to double click the field once, fill out the hours in form-B, close it and get the result in fornm_A. How can I achieve these? Help, please!:(
flyfish
|
January 25th, 2005, 03:07 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
Hi flyfish,
How a you calculating the hour total on form_B? Is this total stored in a control on form_B? What do form_A's and form_B's record sources look like?
- Bob
|
|
|