Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 16th, 2004, 09:51 AM
Rishyraj Rishyraj is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 53 Rishyraj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 29 m
Reputation Power: 4
Combo Help

Hi all,

I have a combo box with three rows.. one for corporation, partneship and Individual. I want depending on my selection in combo box..the respective form to open. Can anyone help.

Does the following procedure right..was just juggling around..i am not good at VB.(PLEASE IGNORE IF THE FOLLOWING DOESNOT MAKE SENSE)

Private Sub Command3_Click()
On Error GoTo Err_Command3_Click
Dim stDocName As String
Dim stLinkCriteria As String

If stDocName = "Corporation" Then
stDocName = "Corporation"
DoCmd.OpenForm stDocName, , , stLinkCriteria
If stDocName = "Partnership" Then
stDocName = "Partnership"
DoCmd.OpenForm stDocName, , , stLinkCriteria
If stDocName = "DBA" Then
stDocName = "DBA"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else

Exit_Command3_Click:
Exit Sub
Err_Command3_Click:
MsgBox Err.Description
Resume Exit_Command3_Click


End Sub

Thank you for your help

Reply With Quote
  #2  
Old December 16th, 2004, 10:36 AM
lwells lwells is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 632 lwells User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 59 m 38 sec
Reputation Power: 4
Hi Rishy,

You are on the right track. Declare your selection from your combobox and use the results of that selection in your criteria for your IF statement

Dim strSelection As String
strSelection = Combobox.Value

If strSelection = "Corporation" Then
stDocName = "Corporation"
DoCmd.OpenForm stDocName
ElseIf strSelection = "Partnership" Then
stDocName = "Partnership"
DoCmd.OpenForm stDocName
ElseIf strSelection = "DBA" Then
stDocName = "DBA"
DoCmd.OpenForm stDocName
End If

Or use the Select Case method

Select Case strSelection
Case "Corporation"
stDocName = "Corporation"
DoCmd.OpenForm stDocName
Case "Partnership"
stDocName = "Partnership"
DoCmd.OpenForm stDocName
Case "DBA"
stDocName = "DBA"
DoCmd.OpenForm stDocName
End Select

The Select Case runs faster than trying to evaluate all the IF Then statements, but would not be noticable in this instance when using just the three variables.

lwells

Reply With Quote
  #3  
Old December 16th, 2004, 11:01 AM
Rishyraj Rishyraj is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 53 Rishyraj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 29 m
Reputation Power: 4
Thank you Iwells, when i am using the following code, it is asking me for the macro name...can you please say what am i doing wrong..the following is the code i am using for on click event.

Private Sub Command4_Click()
On Error GoTo Err_Command4_Click
Dim stDocName As String
Dim stLinkCriteria As String
Dim strSelection As String
strSelection = ComboBox.Value
If strSelection = "Corporation" Then
stDocName = "Corporation"
DoCmd.OpenForm stDocName
ElseIf strSelection = "Partnership" Then
stDocName = "Partnership"
DoCmd.OpenForm stDocName
ElseIf strSelection = "DBA" Then
stDocName = "DBA"
DoCmd.OpenForm stDocName
End If
Exit_Command4_Click:
Exit Sub
Err_Command4_Click:
MsgBox Err.Description
Resume Exit_Command4_Click

End Sub









Quote:
Originally Posted by lwells
Hi Rishy,

You are on the right track. Declare your selection from your combobox and use the results of that selection in your criteria for your IF statement

Dim strSelection As String
strSelection = Combobox.Value

If strSelection = "Corporation" Then
stDocName = "Corporation"
DoCmd.OpenForm stDocName
ElseIf strSelection = "Partnership" Then
stDocName = "Partnership"
DoCmd.OpenForm stDocName
ElseIf strSelection = "DBA" Then
stDocName = "DBA"
DoCmd.OpenForm stDocName
End If

Or use the Select Case method

Select Case strSelection
Case "Corporation"
stDocName = "Corporation"
DoCmd.OpenForm stDocName
Case "Partnership"
stDocName = "Partnership"
DoCmd.OpenForm stDocName
Case "DBA"
stDocName = "DBA"
DoCmd.OpenForm stDocName
End Select

The Select Case runs faster than trying to evaluate all the IF Then statements, but would not be noticable in this instance when using just the three variables.

lwells

Reply With Quote
  #4  
Old December 16th, 2004, 11:17 AM
lwells lwells is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 632 lwells User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 59 m 38 sec
Reputation Power: 4
Hi Rishy,

You need to put the correct name of your combo box in this statement

strSelection = "CorrectNameOfTheComboBox".Value

Also make sure of your correct form name for the stDocName = "CorrectNameOfForm"

lwells

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft Access Development > Combo Help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway