Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #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
Reply With Quote
  #2 (permalink)  
Old April 26th, 2005, 10:45 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,064
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
Reply With Quote
  #3 (permalink)  
Old April 26th, 2005, 10:47 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,064
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
Reply With Quote
  #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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 07:35 PM
How to Inactivate Access While a form is open. joshcallahan1 Access 2 February 7th, 2006 11:02 AM
How to open Access form from VB application? Dmitriy Pro VB 6 1 October 29th, 2004 02:41 AM



All times are GMT -4. The time now is 03:00 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.