Results 1 to 5 of 5
  1. #1
    wmagargle is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    3

    Post If statments??!!

    This seems a bit elementary but I cannot figure this out.
    I need an If (this) and (this or this) then statement. Why wont this code work.
    Thanks in advance for the help.


    Private Sub Command14_Click()

    DoCmd.RunMacro ("mcrDelete")

    Dim cust As String
    Dim tktNo(0 To 3) As String
    Dim tktDate(0 To 3) As String
    Dim tktRep(0 To 3) As String
    Dim orderType(0 To 3) As String
    Dim strikes As Integer
    Dim x As Integer

    Dim db As DAO.Database
    Dim rs As DAO.Recordset

    Dim tbl As DAO.Recordset

    Set db = CurrentDb()
    Set rs = db.OpenRecordset("qryData")
    Set tbl = db.OpenRecordset("tbl3StrikesResults")
    rs.MoveFirst
    strikes = 0


    cust = rs.Fields("cust_no")
    tktRep(0) = rs.Fields("ticket_sls_rep")
    tktNo(0) = rs.Fields("tkt_no")
    tktDate(0) = rs.Fields("tkt_dat")
    orderType(0) = rs.Fields("order_type")

    While Not rs.EOF
    If (cust = rs.Fields("cust_no")) And (orderType(0) <> "repshow" Or orderType(0) <> "road") Then <<<<<--------- NOT WORKING!!!!!!!!!!
    strikes = strikes + 1
    rs.MoveNext
    tktRep(strikes) = rs.Fields("ticket_sls_rep") 'Strike 1
    tktNo(strikes) = rs.Fields("tkt_no")
    tktDate(strikes) = rs.Fields("tkt_dat")
    orderType(strikes) = rs.Fields("order_type")

    If cust = rs.Fields("cust_no") And (orderType(0) <> "repshow" Or orderType(0) <> "road") Then
    strikes = strikes + 1
    rs.MoveNext
    tktRep(strikes) = rs.Fields("ticket_sls_rep") 'Strike 2
    tktNo(strikes) = rs.Fields("tkt_no")
    tktDate(strikes) = rs.Fields("tkt_dat")
    orderType(strikes) = rs.Fields("order_type")

    If cust = rs.Fields("cust_no") And (orderType(0) <> "repshow" Or orderType(0) <> "road") Then
    strikes = strikes + 1
    rs.MoveNext
    tktRep(strikes) = rs.Fields("ticket_sls_rep") 'Strike 3
    tktNo(strikes) = rs.Fields("tkt_no")
    tktDate(strikes) = rs.Fields("tkt_dat")
    orderType(strikes) = rs.Fields("order_type")
    x = 0
    Do While x < 3
    tbl.AddNew
    tbl("cust_no").Value = cust
    tbl("tkt_no").Value = tktNo(x)
    tbl("tkt_dat").Value = tktDate(x)


    tbl("ticket_sls_rep").Value = tktRep(x)
    tbl("order_type").Value = orderType(x)
    tbl.Update
    x = x + 1
    Loop
    x = 0
    Erase tktNo()
    Erase tktDate()
    Erase tktRep()
    Erase orderType()
    End If
    End If
    End If

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Perhaps it would be easier for us to understand if you wrote 3-4 lines telling us WHAT you are trying to do. In plain English first, then when we understand, we can ask for more details, or offer suggestions.
    DoCmd.RunMacro ("mcrDelete")
    Does it have to be a macro?

  3. #3
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,067
    If you break it down to boolean algebra What you want is
    If True And True then
    Your second statement (orderType(0) <> "repshow" Or orderType(0) <> "road") will always evalute to true because if ordertype(0) = "road" then your first statement ordertype(0)<>"repshow" = True same thing if ordertype(0) = "repshow" then the 2nd part = true If ordertype(0) = "something else" then both = true
    So (ordertype(0) <> "repshow" Or order type(0) <>"road") will always evaluate to True no matter what value is in ordertype(0). what you want here is to change the or to and then that section will only evaluate to true if ordertype(0) ="something else"

  4. #4
    wmagargle is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    3
    Awesome, using AND worked like a charm.
    Thanks!!!!!

  5. #5
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,067
    You're welcome

Please reply to this thread with any new information or opinions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums