A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

VB code for Unbound Combo Box with table referenced drop down list



 
 
Thread Tools Display Modes
  #1  
Old April 14th, 2008, 02:19 PM posted to microsoft.public.access.forms
Such a Beginner[_2_]
external usenet poster
 
Posts: 5
Default VB code for Unbound Combo Box with table referenced drop down list

The following code always results in the first command being executed,
regardless of the Item, Anthocyanins, Liver_Lipids, Plasma, or ORAC being
updated. Can someone help me diagnose my code errors?

Private Sub Combo0_AfterUpdate()
If Unbound = Anthocyanins Then
DoCmd.OpenForm "frmAnthocyanins", acNormal
ElseIf Unbound = Liver_Lipids Then
DoCmd.OpenForm "frmLiverLipids", acNormal
ElseIf Unbound = Plasma Then
DoCmd.OpenForm "frmPlasma", acNormal
ElseIf Unbound = ORAC Then
DoCmd.OpenForm "frmORAC", acNormal
End If


End Sub
  #2  
Old April 14th, 2008, 07:26 PM posted to microsoft.public.access.forms
NetworkTrade
external usenet poster
 
Posts: 825
Default VB code for Unbound Combo Box with table referenced drop down list

if your selection is actually those words then they should be surrounded by "
" in your vb

however your selection maybe the bound item in a combobox which is not
actually the text but a number or someother ID...in which case you would use
those values in your vb

--
NTC


"Such a Beginner" wrote:

The following code always results in the first command being executed,
regardless of the Item, Anthocyanins, Liver_Lipids, Plasma, or ORAC being
updated. Can someone help me diagnose my code errors?

Private Sub Combo0_AfterUpdate()
If Unbound = Anthocyanins Then
DoCmd.OpenForm "frmAnthocyanins", acNormal
ElseIf Unbound = Liver_Lipids Then
DoCmd.OpenForm "frmLiverLipids", acNormal
ElseIf Unbound = Plasma Then
DoCmd.OpenForm "frmPlasma", acNormal
ElseIf Unbound = ORAC Then
DoCmd.OpenForm "frmORAC", acNormal
End If


End Sub

  #3  
Old April 14th, 2008, 10:55 PM posted to microsoft.public.access.forms
Steve Sanford
external usenet poster
 
Posts: 190
Default VB code for Unbound Combo Box with table referenced drop down list

This was answered by Clif 4/11/08 4:09PM PST
Subject: Need Help with Code (included in message)

but here is my answer....

The first problem is that the items "Anthocyanins", "Liver_Lipids", "Plasma"
and "ORAC" need to have quotes around them in the code:

Private Sub Combo0_AfterUpdate()
If Unbound = "Anthocyanins" Then
DoCmd.OpenForm "frmAnthocyanins"
ElseIf Unbound = "Liver_Lipids" Then
DoCmd.OpenForm "frmLiverLipids"
ElseIf Unbound = "Plasma" Then
DoCmd.OpenForm "frmPlasma"
ElseIf Unbound = "ORAC" Then
DoCmd.OpenForm "frmORAC"
End If
End Sub

This is assuming there is a text box named "Unbound". If you don't have a
text box named "Unbound", then your code should look something like this:

Private Sub Combo0_AfterUpdate()
If Me.Combo0 = "Anthocyanins" Then
DoCmd.OpenForm "frmAnthocyanins"
ElseIf Me.Combo0 = "Liver_Lipids" Then
DoCmd.OpenForm "frmLiverLipids"
ElseIf Me.Combo0 = "Plasma" Then
DoCmd.OpenForm "frmPlasma"
ElseIf Me.Combo0 = "ORAC" Then
DoCmd.OpenForm "frmORAC"
End If
End Sub


Another option would be using "Select Case" instead of the IF() function:

Private Sub Combo0_AfterUpdate()
Select Case Me.Combo0
Case "Anthocyanins"
DoCmd.OpenForm "frmAnthocyanins"
Case "Liver_Lipids"
DoCmd.OpenForm "frmLiverLipids"
Case "Plasma"
DoCmd.OpenForm "frmPlasma"
Case "ORAC"
DoCmd.OpenForm "frmORAC"
End Select
End Sub

--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


"Such a Beginner" wrote:

The following code always results in the first command being executed,
regardless of the Item, Anthocyanins, Liver_Lipids, Plasma, or ORAC being
updated. Can someone help me diagnose my code errors?

Private Sub Combo0_AfterUpdate()
If Unbound = Anthocyanins Then
DoCmd.OpenForm "frmAnthocyanins", acNormal
ElseIf Unbound = Liver_Lipids Then
DoCmd.OpenForm "frmLiverLipids", acNormal
ElseIf Unbound = Plasma Then
DoCmd.OpenForm "frmPlasma", acNormal
ElseIf Unbound = ORAC Then
DoCmd.OpenForm "frmORAC", acNormal
End If


End Sub

 




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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:35 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.