473,406 Members | 2,336 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

setting criteria on automating email with if then else

16
I've joined this thread hoping to expand my knowledge on visual basic and gain some understanding.
Currently I've been just learning off of other people's codes and I've been just trying to figure out to do something.

I've been trying to add a macro to my current one which would send an email out based upon a yes or no column. But my issue is What happens if i want to have an if then statement that correlates to another column based on its value. I'm thinking of starting my own company one day and was trying to make it so it's a min quantity order.

Ex) Min Quantity Quantity
10 5
5 10
so the first one won't be ordered but the 2nd one will.

Currently i have set it up as a yes or no, which i found online but I want to learn a bit more.
Thanks! you'll see me around the forum a lot more
Jun 10 '10 #1
8 1790
nkf53
16
Ok so I'm going to try again
I know i need an if then statement, but I can't figure this out and have been stumped for a few days.
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. 'Needs Module 2 to set definitions for RAngeHTM so, both moduels needed
  3. Sub Send_Row()
  4.     Dim OutApp As Object
  5.     Dim OutMail As Object
  6.     Dim cell As Range
  7.     Dim rng As Range
  8.     Dim Ash As Worksheet
  9.  
  10.     Set Ash = ActiveSheet
  11.     On Error GoTo cleanup
  12.     Set OutApp = CreateObject("Outlook.Application")
  13.  
  14.     With Application
  15.         .EnableEvents = False
  16.         .ScreenUpdating = False
  17.     End With
  18.  'This determines the email cell, and the lcase cell offset is the distance in # of cells away from this column, therefore you must specify the distance if any changes in columns are made
  19.     For Each cell In Ash.Columns("b").Cells.SpecialCells(xlCellTypeConstants)
  20.         If cell.Value Like "?*@?*.?*" And LCase(cell.Offset(0, 2).Value) = "yes" Then
  21.         'Use this to set range of Cells, as in what columns to put in
  22.  
  23.             Ash.Range("A1:O100").AutoFilter Field:=2, Criteria1:=cell.Value
  24.  
  25.             With Ash.AutoFilter.Range
  26.                 On Error Resume Next
  27.                 Set rng = .SpecialCells(xlCellTypeVisible)
  28.                 On Error GoTo 0
  29.             End With
  30.  
  31.             Set OutMail = OutApp.CreateItem(0)
  32.  
  33.             On Error Resume Next
  34.             With OutMail
  35.                 .To = cell.Value
  36.                  .Subject = "IAT-Blanket Order"
  37.                 .HTMLBody = RangetoHTML(rng)
  38.                 .Display  'Or use Send
  39.             End With
  40.             On Error GoTo 0
  41.  
  42.             Set OutMail = Nothing
  43.             Ash.AutoFilterMode = False
  44.         End If
  45.     Next cell
  46.  
  47. cleanup:
  48.     Set OutApp = Nothing
  49.     With Application
  50.         .EnableEvents = True
  51.         .ScreenUpdating = True
  52.     End With
  53. End Sub

Here is my current code, but I was hoping to find a way to input a code that will allow me to either stop the email when lets say column f is greater thna column g, or even a notification of an error. Thanks, really appreciate it.
Jun 10 '10 #2
vb5prgrmr
305 Expert 100+
Expand|Select|Wrap|Line Numbers
  1. If f > G Then
  2.   'don't do it
  3. Else
  4.   'f is not greater than g
  5. End If
  6.  
  7. If Err.Number > 0 Then
  8.   'error occured
  9. End If
  10.  


Good Luck
Jun 10 '10 #3
MMcCarthy
14,534 Expert Mod 8TB
My knowledge of VB is out of date as I'm afraid my expertise is in VBA.

However from a logic point of view I would create your if statement outside of this module. Set it up as criteria for calling this module.

So something like ...

Expand|Select|Wrap|Line Numbers
  1. If Ash.Columns("g").Cell.Value >= Ash.Columns("f").Cell.Value Then
  2.  
  3.     'send the email
  4.     Send_Row
  5. Else
  6.     'go to next row
  7. End If
Please forgive any syntax errors. From a logical point of view this will only create the email for those rows that satisfy the criteria.

Mary
Jun 10 '10 #4
nkf53
16
Thanks, I think I'm going to just settle it as 2 separate boxes where one is to check the qunantity and the last one is to send them all out. Much appreciated! now wish me luck on coding it lol
Jun 11 '10 #5
nkf53
16
My Brains getting fried right now -.-


Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Sub example()
  4.  
  5.  
  6.  
  7.     Dim cell As Range
  8.     Dim rng As Range
  9.     Dim Ash As Worksheet
  10.      Set Ash = ActiveSheet
  11.       Dim x As Integer
  12.  
  13.       If Ash.Columns("g").cell.Value >= Ash.Columns("f").cell.Value Then
  14.         Ash.Range("A1:O100").AutoFilter Field:=2, Criteria1:=cell.Value
  15.  
  16.             With Ash.AutoFilter.Range
  17.                 On Error Resume Next
  18.                 Set rng = .SpecialCells(xlCellTypeVisible)
  19.     End With
  20.     Select Case Ash.Columns
  21.         MsgBox "Minimum Quantity is not met"
  22.  
  23.  
  24.       End Select
  25.  
  26.  
  27.    End Sub
-nkf
Jun 11 '10 #6
nkf53
16
I decided to make it much simpler, but is there something wrong with my logic statements here?

Expand|Select|Wrap|Line Numbers
  1. Sub msgbox()
  2.  
  3. Dim Source As Range
  4.  
  5.  
  6. If ActiveSheet.Range("f1:f1000").Select > ActiveSheet.Range("g1:g1000").Select Then
  7.  
  8. msgbox ("Min Quantity order not met, Please Check")
  9. End If
  10. Exit Sub
  11.  
  12. End Sub
Jun 14 '10 #7
MMcCarthy
14,534 Expert Mod 8TB
I don't think you can logically work a greater than comparison on a range.
Jun 14 '10 #8
nkf53
16
Yea I figured that out >.>, thanks for the help as always i figured out a way to make it work :)
Jun 14 '10 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: K. Shier | last post by:
when attempting to edit code in a class file, i see the bug "Visual Basic ..NET compiler is unable to recover from the following error: System Error &Hc0000005&(Visual Basic internal compiler...
1
by: Jon | last post by:
I am trying to create a "front end program" to an oracle database and am using visual basic .net to create the program that will accomplish this. What i need to do and what i can't find is the code...
2
by: Ralph | last post by:
I used to have Visual Basic .net std. 2003 installed on WinXP SP1A. But I found it too hard to upgrade WinXP to SP2. Now, I do have WinXP SP2 installed, but I am having problems installing...
0
by: Faez | last post by:
i am using Visual Studio 2005 with Visual Basic language. i have a command button, labelled 'SEARCH' and i want to add the following code to the button; so that when people click on the search...
4
by: sqlguy | last post by:
Why do we have to contact MS for a problem that has been with this compiler from at least the beta of VS 20005. I am so sick and tired of the 30 - 40 clicks it takes to dismiss VS when there is a...
97
by: Master Programmer | last post by:
An friend insider told me that VB is to be killled off within 18 months. I guess this makes sence now that C# is here. I believe it and am actualy surprised they ever even included it in VS 2003 in...
4
by: Chris Asaipillai | last post by:
Hi there My compay has a number of Visual Basic 6 applications which are front endeed onto either SQL Server or Microsoft Access databases. Now we are in process of planning to re-write these...
11
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I have seen the terms Visual Basic 2005 and VB.NET. It seems that sometimes they seem to be referring to the same thing but sometimes they are not. I also run into terms like VB9 and VB10.
3
by: =?Utf-8?B?Rmxhc2hwcm8=?= | last post by:
i have googled this question but cannot find an answer. i'm running windows vista and i'm using Visual Basic Express 2008. i know the build event button SHOULD be in under the compile tag but i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.