Solved

How do I validate two fields instead of one

Posted on 2014-09-29
6
142 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
  • 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

839 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