Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
| Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA 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
  #1 (permalink)  
Old April 26th, 2005, 07:58 AM
Registered User
 
Join Date: Apr 2005
Location: , , United Kingdom.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jonwitts
Default Access VBA - Open a different form...

Please help,

I am trying to have my database open a form if one option from my combo box is selected.

I.E.

In the form "IncidentKind" I have a combo box called "IncidentKind", with multiple options. If the user selects FallofHeight, I want the Form "FallOfHeight" to open. I do not where I am going wrong, please help.

Jon Witts
  #2 (permalink)  
Old April 26th, 2005, 10:45 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Hi,

   This is easy. The combo box is capturing a primary key for the value FallOfHeight, I assume. I also assume the user selects a field from the combo box, and then clicks a button to open the other form. Is there already a form that is opened somehow?

   Anyway, you have to capture the value from the combo box, then check it in an If Then End If, like this:

(This example assumes that 1 is the PK for FallOfHeight.)

'==========
Private Sub btnYourButton_Click()
On Error GoTo Err_btnYourButton_Click

    Dim stDocName As String
    Dim intMyComboBox As Integer

    intMyComboBox = Me.MyComboBoxName

    If intMyComboBox = 1 Then
      stDocName = "frmFallOfHeight"
      DoCmd.OpenForm stDocName
    Else
      stDocName = "frmDefaultForm"
      DoCmd.OpenForm stDocName
    End If


Exit_btnYourButton_Click:
    Exit Sub

Err_btnYourButton_Click:
    MsgBox Err.Description
    Resume Exit_btnUserName_Click

End Sub
'=====

You can also add link criteria if you need to open to a specific record based on the combo box selection, or another combo box or text box selection.

HTH


mmcdonal
  #3 (permalink)  
Old April 26th, 2005, 10:47 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Hi,

   Sorry, I used MyComboBox as the name of the box you have called "IncidentKind."

   Also, you can put this on the combo box's After Update event, but I usually put this on a button's on click event, to give the user the option to open the next for or not.

HTH


mmcdonal
  #4 (permalink)  
Old April 27th, 2005, 06:47 AM
Registered User
 
Join Date: Apr 2005
Location: , , United Kingdom.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jonwitts
Default

Thanks for your prompt reply. I think I see where I was going wrong, and I am going to try and impliment this in my database. I will let you know how it goes.

Jon Witts


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem using ADO to open form in MS Access apike VBScript 3 May 2nd, 2006 06:25 AM
Access VBA - Controlling Text boxes in a form Scripts82 Access VBA 4 February 8th, 2006 08:35 PM
How to Inactivate Access While a form is open. joshcallahan1 Access 2 February 7th, 2006 12:02 PM
How to open Access form from VB application? Dmitriy Pro VB 6 1 October 29th, 2004 02:41 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.