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

Subforms-New record 1

Status
Not open for further replies.

rookiedev

Technical User
Jul 23, 2002
115
US
I have a Sub form on a Tab Form does not go to new record when focus is moved to a new employee. I have an employee time subform that I enter daily time into. When I click the next record button to move to a new employee I can't figure out how to give focus to the time subform and automatically go to a new record to enter that person's time.
nberryman was correct in his advice and I also placed the DoCmd.GoToRecord , , acNewRec on the form opened. That worked great when I first opened the form....went right to a new record.I thought maybe I needed to somehow add code to the Next record command button to set the focus to the time subform and then go to a new record but I have no idea how to go about it with the code that is already there for "On Click"
Can you help me? Pleeeeez
visitor
 
The name of the subform is Time and the first field is date. The form is setup to go to Date as the first tab.Is this what you mean for me to do?

This is the event on the Next Record Command Button on the main form:

Private Sub Next_Record_Click()
On Error GoTo Err_Next_Record_Click
DoCmd.GoToRecord , , acNext
Time.SetFocus
Date.SetFocus

Exit_Next_Record_Click:
Exit Sub

Err_Next_Record_Click:
MsgBox Err.Description
Resume Exit_Next_Record_Click

End Sub

I get an error message "object required" Maybe I am misunderstanding.
Thanks!
RookieDev
 
Hi Rookie
Try
Private Sub Next_Record_Click()
On Error GoTo Err_Next_Record_Click
DoCmd.GoToRecord , , acNext
forms!Time.SetFocus 'This is your subform
Me!Date.SetFocus 'This is the field on that subform

Exit_Next_Record_Click:
Exit Sub

Err_Next_Record_Click:
MsgBox Err.Description
Resume Exit_Next_Record_Click

End Sub
 
Hi hermanlaksko
I tried to set the on click event the way you said but I kept getting an error message

"There is an invalid method in an expression" For example, you may have tried to use the Print method with an object other than Report or debug."

and then the subform would not let me add any records. I thought maybe it had something to do with the Me!Date.setfocus and not fully identifying the path of the subform so I tried this:

Private Sub Next_Record_Click()
On Error GoTo Err_Next_Record_Click
DoCmd.GoToRecord , , acNext
Forms![Employees]![Time].SetFocus
DoCmd.GoToRecord , , acNewRec
Exit_Next_Record_Click:
Exit Sub

Err_Next_Record_Click:
MsgBox Err.Description
Resume Exit_Next_Record_Click

End Sub

This will actually work except for the fact that the first record in Employees (Main Form) does not show all the records in the Time (subform) datasheet-only a new record displays.

When I click the Next Record command button a new instance of the Time form opens in continueous form view.

If I close the second instance then I am able to add a new record to the Time subform and everything seems to be fine. The next time I click the Next Record Command button the Time Subform again opens a second instance of the subform.
Do you think I need some kind of Dim statement in the event?

It seems like I am almost there except for the fact that this second instance of the form keeps opening and I fear that the records will not stay insinc.

Any suggestions you have will be greatly appreciated.
Thanks!
RookieDev
 
Hi RookieDev

On Error GoTo Err_Next_Record_Click
DoCmd.GoToRecord , , acNext 'I think your problem is here, this line should not be here as this would refer to your main form.
Forms![Employees]![Time].SetFocus
DoCmd.GoToRecord , , acNewRec
If you still cant it to work for you I will give you my email and we will have a look at it off line.
So we can get the darn thing up and roll ;-D
 
Hi hermanlaksko!
I have to keep the reference to the main form because I need to move to the next employee and then enter a new time record. It was just a bit cumbersome to have to keep clicking on the new record indicator and then in the date field. I'm going to take another look and see if I compile and save the modules if the error will go away. I'll let you know if it does. The fact that another instance of the subform kept opening baffled me. I sure didn't expect that to happen. I just thought the focus would go to the exsisting form. It's a mystery to me. Thanks for your help. I'll let you know what happens.
RookieDev
 
hermanlaksko!
I'm so excited! I think we almost have it now! Compiling the modules seemed to do the trick with one exception..... When I first open the employee's form the time subform does not go to a new record. It goes to the first record. Do you think if I put DoCmd.GoToRecord , , acNewRec on the open event of the time subform that will fix it? I'm almost afraid to do anything else because we've made so much progress here. Let me know if you think that will do it.
Thanks sooooo much!
This deserves a star
RookieDev
 
Ok :-D

If you want your form to goto a new record, then I think that your Docmd.... is the trick, and yes go right ahead I would use docmd..... aclast but thats just me ;-).
I used to have this problem on how to open a form and where to drop the user, then I developed a small function that saves the currentno to a tbl and when the user opens the form again I drop hem/her where they left it.
It seems normal to end users and no one has ever mentioned it to me, but I am sure that they would mention it if I did not drop them where they left off :-D.
All the best Herman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top