Need Help with Code (included in message)

S

Such a Beginner

My Unbound Combo Box is a dropdown list of Anthocyanins, Liver Lipids,
Plasma, and ORAC. The code below always results in the first DoCmd statement
being executed. In other words, if I update the Unbound box with any word
from the above list, I get the same result. Could someone please diagnose my
code problem (see below)?

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
 
C

Clif McIrvin

I think this is one I can answer ... so I'll give it a go. This
information comes from the Access VB help for Combo Box Object; then
look at the Value property.

In general, to get the value that belongs to a combo box use
the .Value property when referring to it (I'll edit your code sample
in a minute) _but_ there are exceptions to that -- that's why I refer
you to the help file.


I think your code needs to look like this (indents added to assist in
seeing what the IF statements are doing:)

Private Sub Combo0_AfterUpdate()
If Me.Combo0.Value = "Anthocyanins" Then
DoCmd.OpenForm "frmAnthocyanins", acNormal
ElseIf Me.Combo0.Value= "Liver Lipids" Then
DoCmd.OpenForm "frmLiverLipids", acNormal
ElseIf Me.Combo0.Value= "Plasma" Then
DoCmd.OpenForm "frmPlasma", acNormal
ElseIf Me.Combo0.Value= "ORAC" Then
DoCmd.OpenForm "frmORAC", acNormal
End If
End Sub


Note that I didn't use your variable "Unbound" -- I have no idea what
it means, and Me.Combo0.Value refers to the combo box that this
procedure was called by.

Also note that I used double quotes ( " ) to tell the VB compiler that
Anthocyanins, Liver Lipids, Plasma, and ORAC are constants (that is,
actual values), not variable names.


HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top