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!

Moving between forms 1

Status
Not open for further replies.

carlosguill

Technical User
Dec 23, 2003
31
US
Hello, I have a problem about returning to related froms.
I have a form that opens another form with a command button, what I need to do after entering data in the second form is to return to the first form with either the return key or tab key to start a new record in form 1 and repeat the process between the two forms. The tables associated to these forms are linked in a one to one relationship. I will appreciate any help with this.

Thanks,

Carlos
 
How are ya carlosguill . . . . .

In theA [blue]fterUpdate[/blue] event of the [blue]last edited control[/blue], try this:
Code:
[blue]Forms![purple][b]CallinfFormName[/b][/purple].SetFocus
DoCmd.RunCommand acCmdRecordsGoToNew
DoCmd.Close acForm, "[purple][b]OpenedFormName[/b][/purple]"[/blue]


Calvin.gif
See Ya! . . . . . .
 
Hi AceMan1,
thank you for your idea, I tried it but it is not working, here is what I put in the code, may you can help me figure out what I am doing wrong. Thank you

Private Sub DateofTransfer_AfterUpdate()

Forms![FOLLOW UP].SetFocus
DoCmd.RunCommand acCmdRecordsGoToNew
DoCmd.Close acForm, "Closing Info"
End Sub
 
carlosguill . . . . .

Fully Tested the code. Although it [blue]works fine[/blue], made some changes to prevent an error and a save popup message. Change code to:
Code:
[blue]   Forms![FOLLOW UP].SetFocus
   
   If Not Forms![FOLLOW UP].NewRecord Then
      DoCmd.RunCommand acCmdRecordsGoToNew
   End If
   
   DoCmd.Close acForm, "Closing Info", acSaveYes [/blue]
[ol][li][purple][Follow Up][/purple] should be the form with the button.[/li]
[li][purple]"Closing Info"[/purple] should be the form opened by the button[/li]
[li]The code should be in the [purple]AfterUpdate event[/purple] of the form opened by the button.[/li][/ol]
[purple]If you still have problems, post the code in your button along with a description of what didn't work . . .[/purple]


Calvin.gif
See Ya! . . . . . .
 
Thank you very much AceMan1, that worked perfectly.
 
Sorry to come back here for more help, but I am stuck now in another step of building these forms. What I am trying to do now is to move from the first subform in the Tab Control to the second subform also in the tab control. I set up the code based on suggestions given here for my previous situation, but this time I am getting the following error "A problem occurred while microsoft access was communicating with the Ole Server or ActiveX Control.
*The expression may not result in the name of a macro, user-defined function or event procedure
**There may have been an error evaluating the event.
I am using the following code in the KeyDown event:

If KeyCode = Key_Tab Then
KeyCode = 0
Me!SWHealthEducation.HealthEduID.SetFocus
Exit Sub

The reason I am trying to use the Tab Key for this operation is because more than one record can be entered in this subform, so if I want to enter another record I can do it after hitting the Enter Key. All of these are guesses, because I am not a programmer.
Any help resolving this problem will be appreciated.
 
carlosguill . . . . .

Sorry to get back so late . . .

Since the Tab key is used alot by most users, the key combination for switching between the two subforms is now:
[blue]Ctrl + Alt[/blue]. And yes . . . you can switch between both subforms! Here we go . . . In any code that follows, [blue]you![/blue] substitute proper names in [purple]purple[/purple].
[ol][li]Open one of the subforms in [blue]form design view[/blue] an do the following:
[ol a][li]Set the forms [blue]KeyPreview[/blue] property to Yes.[/li]
[li]In the forms [blue]KeyDown[/blue] event, copy/paste the following code:
Code:
[blue]   Call SubFocus(Shift, "[purple][b]subFormName[/b][/purple]")[/blue]
[/li][/ol][/li]
[li]Peform the above steps for the 2nd subForm.[/li]
[li]In a [blue]module[/blue] in the [blue]modules window[/blue], copy/paste the following routine:
Code:
[blue]Public Sub SubFocus(Shift As Integer, curForm As String)
   Dim frm As Form, sfrm1 As String, sfrm2 As String
   
   If (Shift And acCtrlMask) > 0 And (Shift And acAltMask) > 0 Then
      sfrm1 = "[purple][b]subFormName1[/b][/purple]"
      sfrm2 = "[purple][b]subFormName2[/b][/purple]"
      
      Set frm = Forms![purple][b]MainFormName[/b][/purple]
      
      If curForm = sfrm1 Then
         frm(sfrm2).SetFocus
      ElseIf curForm = sfrm2 Then
         frm(sfrm1).SetFocus
      End If
      
      Set frm = Nothing
   End If

End Sub[/blue]
[/li][/ol]
[purple]Thats it . . . give it a whirl & let me know . . .[/purple]

Calvin.gif
See Ya! . . . . . .
 
Hi AceMan1,
I tried your suggestion, but as soon as I hit the Ctrl key I get the same message I mentioned above. Any ideas what can be causing that?
 
carlosguill . . . . .

Post the [blue]SubFocus[/blue] routine & the code you have in the [blue]KeyDown[/blue] event, as you have them. (I fully tested what Igave you!).

Calvin.gif
See Ya! . . . . . .
 


This is the code in subform2, after I set up the KeyPreview to yes.

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Call SubFocus(Shift, "FUpIssues")

End Sub

This is the code in the module

Public Sub SubFocus(Shift As Integer, curForm As String)
Dim frm As Form, sfrm1 As String, sfrm2 As String

If (Shift And acCtrlMask) > 0 And (Shift And acAltMask) > 0 Then
sfrm1 = "FUpIssues"
sfrm2 = "SWHealthEducation"

Set frm = Forms![FOLLOW UP]

If curForm = sfrm1 Then
frm(sfrm2).SetFocus
ElseIf curForm = sfrm2 Then
frm(sfrm1).SetFocus
End If

Set frm = Nothing
End If

End Sub

Before I was getting the same error message as I explained, but now is not doing anything. Thanks for putting your time in looking into this.
 
carlosguill . . . . .

The mainform the subforms are on (forget the tab control) is [blue]FOLLOW UP[/blue]?

Calvin.gif
See Ya! . . . . . .
 
FOLLOW UP is the mainform, and I have a tab control with FUpIssues subform in the first page and SWHealthEducation in the second page. Another important thing that I forgot to mention before is that the data entry rutine would be as follows.
From Mainform (FOLLOW UP) moves to Subform1 (FUpIssues) (Which can have several records for each parent record), moves to Subform2 (SWHealthEducation) (only one record at a time) moves to start a new record in Mainform (FOLLOW UP).
 
carlosguill . . . . .

[ol][li]As far as the error is concerned, you have to have some trying to reference an ActiveX control. Do a search in VB for this.[/li]
[li]Did you remove the [blue]origional KeyDown[/blue] code you had?
What I gave you can only trigger on [purple]Ctrl + Alt![/purple].[/li][/ol]

Calvin.gif
See Ya! . . . . . .
 
I did removed the KeyDown code, and I have not been able to find anything about the ActiveX control.
 
carlosguill . . . . .

and is the debugger stopping on a line of code?

If so, post it . . .

Calvin.gif
See Ya! . . . . . .
 
carlosguill . . . . .

Set a break point at [blue]Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)[/blue] for both subforms and see if the code is executed at all.

If it is, [purple]single step[/purple] until the error is raised and post that line.

BTW, is [blue]Key Preview[/blue] set in the [blue]mainform[/blue]?

Calvin.gif
See Ya! . . . . . .
 
I set the break points, the code is not executed and I got the same message, but this time the message appeared when I hit the enter key.
key Preview is set to yes in the main form.
 
carlosguill . . . . .

No . . . No . . . No! Key Preview should be set in the subforms!

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top