Need a little help with VBA. I have written the below and what i want it to
do, is from the main form if i pick a cylinder (Drop down box) then it goes
to a different form in "Add Mode", but if i pick a Tank then i want it to go
to a different form in "add mode".
But the below is not working? Could someone please help.
Thanks
Sarah
Private Sub Multiif()
If Job_Installable.[Column](1) = "Cylinder" Then
Forms!OrderForm.ctlSubForm.Form!Controls.NewData
Forms!
[tblJob_Consumables SubForm]![Job Consumable Consumable ID].ControlSource =
"qryConsumables"
ElseIf Job_Installable.Column(1) = "Tank" Then
[tblJob_Consumables SubForm]![Job_Consumable Consumable ID].ControlSource =
"qryConsumableTank"
End If
Me.tbl_Job_Consumable_SubForm.Requery
End Sub
That's the main thing I think you're getting wrong - you're not taking the
built-in help available!
Firstly, I always set "Option Explicit" at the top of a module, so that any
object which isn't declared throws a compile error. Secondly, I never (not
even for the most trivial Sub or Function) omit error handling code. See
this: http://allenbrowne.com/ser-23a.html - for most procedures it's enough
to use the nine numbered lines.
Then set a breakpoint in your code (bring up the VBA Editor using Alt-F11
and click in the margin). When the execution point hits that line it'll
raise the VBA editor and you can step through line by line. You'll see at
which point execution jumps to the error-handler and see a message saying
what the runtime thinks is wrong. This is surprisingly easy and
informative - you can hover over a variable and view its value, and there
are all sorts of other neat stunts you can pull.
Also, it's worth mentioning the "Compile" option under the Debug menu in the
VBA editor. Before running the code, check it compiles!
Finally, I have a nagging doubt that changing the ControlSource at run-time
is going to lead to the best solution. Perhaps you could use (and
hide/show) different subforms? But that's a different question...
Hope that helps!
Phil, London
"Sarah" <Sa...@discussions.microsoft.com> wrote in message
news:94F080E9-6F56-478D...@microsoft.com...
What do you mean by "not working"? Do you get an error message?
When you say "go to a different form", what do you mean? Do you want to open
one of two different forms on top of you main form, or do you want to select
which form is displayed in a sub-form control on the main form?
Your code does neither - the ControlSource property does not indicate which
form is to be used as the subform. To do that, look at the SourceObject
property of the subform control.
HTH
John
--
John Goddard
Ottawa, ON Canada
jrgoddard at cyberus dot ca
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-gettingstarted/200911/1
Thanks
Sarah
"J_Goddard via AccessMonster.com" wrote:
> .
>