dbTalk Databases Forums  

IF/ELSE VBA

comp.databases.ms-access comp.databases.ms-access


Discuss IF/ELSE VBA in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Joe Smith
 
Posts: n/a

Default IF/ELSE VBA - 11-12-2010 , 08:45 AM






I want to run a macro depending on what a user enters in a specific
field. If a user enters a code (i.e., 1-A-CB939) that contains the
letters "CB", I want to run macro1. Else, if a user enters a code
(i.e., 9-B-ME483) containing the letters "ME" into the Code field, I
want to run macro2.

I already figured out the SQL part (Like "*CB*" or Like "*ME*"). I
just need help with the IF/ELSE VBA syntax to accomplish what I
explained above. Thank you very much in advance.

Reply With Quote
  #2  
Old   
Jon Lewis
 
Posts: n/a

Default Re: IF/ELSE VBA - 11-12-2010 , 09:06 AM






You don't need SQL, try the Instr VBA function in the After Update event of
your text box (replace YourTextBox with the actual name of the text box):

If InStr(Me.YourTextBox, "CA") Then
DoCmd.RunMacro "macro1"
ElseIf InStr(Me.YourTextBox, "ME") Then
DoCmd.RunMacro "macro2"
End If

HTH


"Joe Smith" <bucbarrydb (AT) gmail (DOT) com> wrote

Quote:
I want to run a macro depending on what a user enters in a specific
field. If a user enters a code (i.e., 1-A-CB939) that contains the
letters "CB", I want to run macro1. Else, if a user enters a code
(i.e., 9-B-ME483) containing the letters "ME" into the Code field, I
want to run macro2.

I already figured out the SQL part (Like "*CB*" or Like "*ME*"). I
just need help with the IF/ELSE VBA syntax to accomplish what I
explained above. Thank you very much in advance.

Reply With Quote
  #3  
Old   
Joe Smith
 
Posts: n/a

Default Re: IF/ELSE VBA - 11-12-2010 , 09:17 AM



On Nov 12, 10:06*am, "Jon Lewis" <jon.le... (AT) cutthespambtinternet (DOT) com>
wrote:
Quote:
You don't need SQL, try the Instr VBA function in the After Update event of
your text box (replace YourTextBox with the actual name of the text box):

If InStr(Me.YourTextBox, "CA") Then
* * DoCmd.RunMacro "macro1"
ElseIf InStr(Me.YourTextBox, "ME") Then
* * DoCmd.RunMacro "macro2"
End If

HTH

"Joe Smith" <bucbarr... (AT) gmail (DOT) com> wrote in message

news:a8d882da-d1d2-4b46-acd4-f761163a9f39 (AT) n32g2000prc (DOT) googlegroups.com...



I want to run a macro depending on what a user enters in a specific
field. If a user enters a code (i.e., 1-A-CB939) that contains the
letters "CB", I want to run macro1. Else, if a user enters a code
(i.e., 9-B-ME483) containing the letters "ME" into the Code field, I
want to run macro2.

I already figured out the SQL part (Like "*CB*" or Like "*ME*"). I
just need help with the IF/ELSE VBA syntax to accomplish what I
explained above. Thank you very much in advance.- Hide quoted text -

- Show quoted text -
Thanks alot, Jon. That helped tremendously.

Reply With Quote
Reply




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 On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.