Solved

How do I validate two fields instead of one

Posted on 2014-09-29
6
144 Views
Last Modified: 2014-10-05
Can someone assist me with the correct syntax for validating two fields in a database table. The attached document details the code I am using which works and validates if a payment method already exists in my table e.g. Cash, Credit Card etc (i.e. a single field). What I want to do before I save my record is to validate if two fields in the same table exist e.g. How Paid and Payment Category. So if "Cash" (How Paid) and "General" (Payment Category) exists I want to display that this record already exists. I have tried adding the extra code but get compile errors. In the attached code I need to include Me.PaymentCategory.Text somehow/somewhere with Me.HowPaid.Text so that it checks to see if both exist in the one record. I am using Ironspeed Designer with a MSSQL 2012 backend database.
Validate.doc
0
Comment
Question by:sdms2004
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 40349664
I'd post a text file rather than a doc file - less likely to have malware embedded in it.  (I'm not going to look into your attachment).

>>So if "Cash" (How Paid) and "General" (Payment Category) exists I want to display that this record already exists.

A simple and condition for an if statment, something like

IF HowPaid = "Cash" AND PaymentCategory = general THEN  
  'record exists - warn user
ELSE
  'add a new record
END IF
0
 

Author Comment

by:sdms2004
ID: 40350018
Thanks Andy, sorry about the word doc. I understand the principle but its the syntax. I have attached the code I am using in a plain text file
Steve
0
 

Author Comment

by:sdms2004
ID: 40350026
Andy
Forgot to attach the file
Steve
validate.txt
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 40350170
No need to apologise.

>>Dim whereStr As String = SD12HowPaidTable.HowPaid.InternalName & "='" & Me.HowPaid.Text & "'"

I think something like the following should be OK (the devil is in the details):

Dim whereStr As String = SD12HowPaidTable.HowPaid.InternalName & "='" & Me.HowPaid.Text & "' AND " & SD12HowPaidTable.PaymentCategory & "=general"
I don't know how you define the general (integer, text...) or how you have named things but the principal is just connect the parts of the where clause with an AND.  (also things like OR and NOT should be supported if you required those for other conditions).
0
 

Author Comment

by:sdms2004
ID: 40358330
Andy
Thanks, I will try it tonight when I get home and let you know how I go.
Steve
0
 

Author Comment

by:sdms2004
ID: 40362085
Andy
Thanks for pointing me in the right direction, got it to work
Steve
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question