Wrox Programmer Forums
|
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
 
Old May 3rd, 2005, 03:04 AM
Registered User
 
Join Date: Apr 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jonwitts
Default Access VBA help needed...!!

Hi I currently making a accident reporting database for my employers. I have built all of the tables and forms and have set up the relationship model. However I am currently have some problem with the VBA code of my buttons. On the bottom of each form I have a button that will save the form, close it and then open the next form in the input process. However on some forms depending on one of the fields selected on that form, I need a different form to open than all other options. I thought I would be able to this with a "If Else" command.

Here is the code I am using at the moment, which does not appear to help...

Private Sub SaveRecord_Click()

If Me.IncidentKind = "FallofHeight" Then
DoCmd.Save
DoCmd.Close
DoCmd.OpenForm "FallofHeight"

Else


DoCmd.Save
DoCmd.Close
DoCmd.OpenForm "Recording"

End If

End Sub
 
Old May 3rd, 2005, 01:23 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Jon: Use indenting!

You take some identical steps, irrespective of the condition, so your intent would be easier to follow (both for you and for others) if the conditional step was all that was inside the “If” block:
Code:
Private Sub SaveRecord_Click()

    DoCmd.Save
    DoCmd.Close

    If Me.IncidentKind = "FallofHeight" Then
        DoCmd.OpenForm "FallofHeight"
    Else
        DoCmd.OpenForm "Recording"
    End If

End Sub
You could even make it clearer with
Code:
Private Sub SaveRecord_Click()

    Dim NextForm As String

    If Me.IncidentKind = "FallofHeight" Then
        NextForm = "FallofHeight"
    Else
        NextForm = "Recording"
    End If

    DoCmd.Save
    DoCmd.Close
    DoCmd.OpenForm NextForm 

End Sub
What kind of a thing is Me.IncidentKind?
You say “Here is the code I am using at the moment, which does not appear to help...”: What does it do? What is the result that you get that is not helpful?
 
Old May 4th, 2005, 02:26 AM
Registered User
 
Join Date: Apr 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jonwitts
Default

Me.IncidentKind is a drop down combination box with "FallofHeight" being one of the posible selections. The problem I am getting is that even if "FallofHeight" is selected in Me.IncidentKind drop down box, the form "Recording" is still opening when the code is executed.

Do I need to include an error catcher in this too?
 
Old May 4th, 2005, 08:50 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 155
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to leehambly
Default

what value is stored in your combo box?

Is it the id of the lookup or the actual text "FallofHeight"?

If this isnt working, I would guess it is the id of the lookup rather than the actual text, or your code value "FallofHeight" doesnt match the value in the combo box.
 
Old May 4th, 2005, 09:41 AM
Registered User
 
Join Date: Apr 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jonwitts
Default

Thanks for this.. It was indeed that I was trying to use the id of the lookup as the value.. Have changed it now and it all works beautifully.

Cheers.





Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA filtering help needed! simpage_uk00 Excel VBA 1 April 12th, 2007 10:59 AM
Help Needed to write vba for Pivot Table in Excel sunny76 Excel VBA 1 June 28th, 2005 01:44 AM
Help Needed on VBA lyndon Access VBA 5 April 14th, 2005 07:49 PM
Saving Excel VBA code gives problems - Help needed mjaitly Excel VBA 0 April 14th, 2004 07:23 AM
Word VBA Syntax Needed SerranoG VB How-To 4 October 28th, 2003 02:16 PM





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