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

Linking Forms to Forms

Status
Not open for further replies.

Graystorm2

Technical User
Apr 2, 2007
10
US
While testing the database I been asking about I found out that I dont like having the queries on the same form that handles data entery. It just leads to user mistakes.

In mind the best way to do this is to have a form come up that simply has a com buttons that give the user a choice "Data Entery" or "Search Database" which takes the user to the right form. Acourse the forms also have to be linked to one another for eassy access.


My question can this be done or am I thinking to much like a website. If it can be done can someone point me in the right direction.

 
This should be no problem.

On each of your 3 forms, you'll need at least 2 buttons: One to go to each of the other 2 forms.

If you use the control wizard for setting up the buttons, it should guide you very easily through what you are describing.

The VBA, if you're wanting to hand-code it, would be:

Assuming for example that this code would be on Form1
Code:
Private Sub GoToMain_Click()
  DoCmd.OpenForm "frmMain"
End Sub

Private Sub GoToForm2_Click()
  DoCmd.OpenForm "frmForm2"
End Sub

Then, if you want the current form to close, you could add something like this in:

Code:
Private Sub GoToMain_Click()
  DoCmd.Close
  DoCmd.OpenForm "frmMain"
End Sub

Private Sub GoToForm2_Click()
  DoCmd.Close
  DoCmd.OpenForm "frmForm2"
End Sub

The last example will close your current form, and then open the other form all in code, so that there is only 1 form open at any given time.


--

"If to err is human, then I must be some kind of human!" -Me
 
How are ya Graystorm2 . . .

Agree with [blue]kjv1611[/blue] on the two buttons per form. However I suggest a common routine that can be called by all the buttons.

In the code module of the form, copy/paste the following routine:
Code:
[blue]Public Sub frmCtl(frmName As String)
   Dim frmHld As String
   
   frmHld = Screen.ActiveForm.Name
   DoCmd.OpenForm frmName
   DoEvents
   DoCmd.Close acForm, frmHld, acSaveYes [green]'close calling form.[/green]
   
End Sub[/blue]
A call from one of the buttons [blue]Click[/blue] event would look like:
Code:
[blue]   Call frmCtl("[purple][b][i]FormNameToOpen[/i][/b][/purple]")[/blue]
[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
Graystorm2,

I'll have to concede that TheAceMan1's code setup is probably the most efficient and effective way to go about it. Let us know if you do not understand his method above. It should be very simple to implement.

--

"If to err is human, then I must be some kind of human!" -Me
 
Thanks guys for this help. Unfortuntly for me I have yet to learn how to code...but I might just have to. I am going to have to try the wizard to see how that works. Which leads me to building forms. BTW do I need Visual Basic for coding.
 
The coding of the forms is Visual Basic. It's VBA (Visual Basic for Applications) - it's basically a Visual Basic setup that has various objects and such already setup for each Office application (Excel, Word, Access, etc).

If you start with the Wizard, some of the code will be there for you. Then, for the rest of the code, you can take it a step at a time, use the help file, use the web (search engines), use tek-tips, etc. And when typing the code, VBA will give you some menus of items that it already thinks you may use. I forget the term, but basically, if you type "DoCmd." for instance, as soon as you type the period, VBA will populate a list right there showing you all the possible choices that it knows about right off.

--

"If to err is human, then I must be some kind of human!" -Me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top