473,378 Members | 1,410 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,378 software developers and data experts.

Multiple Fields Validation in Access 2010 Form

2
HI,

I have one table called transaction where in i am storing transaction.

There are different customer for different type of journals subscription.

We have journals subscription start date and end date in same transaction table.

What is need is while in entry as soon as users select subscription start date it should first check whether customer is already there in the table if not then let him enter data and if customer already exists then it should check with journal name if it no then let him enter data and if journal name exists it should check the subscription end date and compare it with forms subscription start date and start date is greater then the end date of find record then let him enter data or other wise popup message that record already exists.

I know i have to put vba code in subscription start date after update option but i dont know what to put in code to check all this.

Please help me out in this.

Thanks

Pagi
Jan 5 '14 #1
3 2286
NeoPa
32,556 Expert Mod 16PB
What if, when the Start Date has been entered, the other information that you want to check hasn't been entered yet?

What if any of the dependent information changes after the check has been done?

It doesn't seem that you've given your specification enough thought yet. It is not a good idea to look for an answer until at least the question is properly understood.
Jan 5 '14 #2
pagi
2
Hi,

I have put following code in subscription date which will check the previous filed entered but i am getting an error as follow.

run time error 3075 Syntax Error in string query expression ['Journal_name]='Candid'.

please find below my code

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtSubscriptionStartDate_AfterUpdate()
  2.   If DCount("cust_id", "Transaction", "cust_id= " & Me.cust_id) > 0 And DCount("[Journal_name]", "Transaction", "[Journal_name]='" & Me![Journal_name] & "") > 0 Then
  3.     MsgBox "Name Is Already In Database!"
  4.     Cancel = True
  5.     Forms!TransactionDetails!txtSubscriptionCustomerName.SetFocus
  6. End If
  7. End Sub
Journal_name filed is a text filed which is linked to journal master table where all the journal name are there.
Jan 6 '14 #3
zmbd
5,501 Expert Mod 4TB
The error is telling you that there is something wrong with the string that you are using in the dcount function.

You're missing the closing quote on the string... see my correction below.

You've stumbled upon one of my pet peeves by building the criteria string within the command - and it's not your fault because that's how a majority of examples show how to use the command.
Instead I suggest that you build the string first and then use the string in the command. Why you might ask, because you can then check how the string is actually resolving; thus, making troubleshooting the code so much easier as most of the time the issue is with something missing or not resolving properly/as expected within your string.
So to use your code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtSubscriptionStartDate_AfterUpdate()
  2. DIM strSQLCID as string
  3. DIM strSQLJN as string
  4. Dim lngCountCustID As Long
  5. Dim lngCountJournalName Long
  6. '
  7. strSQLCID = "cust_id= " & Me.cust_id) > 0
  8. lngCountCustID = DCount("cust_id", "Transaction", strSQLCID)
  9. '> debug.print strSQLCid
  10. '
  11. strSQLJN = "[Journal_name]='" & Me![Journal_name] & "'") > 0
  12. '> debug.print strSQLJN
  13. '
  14. lngCountJournalName = DCount("[Journal_name]", "Transaction",strSQLJN ) 
  15. '
  16. '  If lngCountCustID > 0 And lngCountJournalName > 0 Then
  17.     MsgBox "Name Is Already In Database!"
  18.     Cancel = True
  19.     Forms!TransactionDetails!txtSubscriptionCustomerName.SetFocus
  20.    End If
  21. End Sub
  22.  
Now I used strSQLCID and strSQLJN here for clarity; however, I would normally just recycle a single string varible.
Note the '> Debug.Print.... lines. Uncomment and remove the ">" when the code is ran, you can press <Ctrl><G> and see how these strings are resolving.

I also pull the dcount() out of the IF..Then structure, once again, this is to make troubleshooting easier as now you can debug.print the value if needed to see what is happening within the count.

I know that many will complain about the extra code and processor times etc... we're no longe in the CBM-Vic20 days where 5K-RAM and a ultra-slow processor was the norm. These extra lines are hardly a blip in the processor and it is (IMHO) better to write code that is well commented and easy to troubleshoot that to compound things.
(^_^)
Jan 6 '14 #4

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

Similar topics

2
by: sierra7 | last post by:
It seems Access 2010 is associating an 'input mask' or field type with a combo box when a form is opened, even though there is no Format setting on the control. I have a form which has been...
5
by: neelsfer | last post by:
I got a new work laptop last week with Access 2010 pre-loaded.I also installed the new Office 2010 service pack 1. I then loaded 2 of my regularly used Access 2007 + service pack 2 applications on...
4
by: jbrumbau | last post by:
Hello, In Access 2010/2007, how do you prevent users from flipping into design view from the ribbon? I do not want to hide the entire ribbon (DoCmd.ShowToolbar "Ribbon", acToolbarNo) or even the...
4
beacon
by: beacon | last post by:
Hi everybody, My title may not exactly describe my issue, so please forgive my lack of creativity today. I've got a database that was created in Access 2003 that I've opened in Access 2010. I...
1
by: Meemalef | last post by:
I have microsoft access 2010 database, recently i've changed some labels fonts .. but when i close the database and reopen it i find labels changes automatically to a different font ... how...
11
by: Redbeard | last post by:
I have just upgraded to Access 2010 (64 bit) from Access 2007. There were a few minor issues in the database which I have resolved but this one piece of code just won’t work. I do not write VBA but...
2
by: Redbeard | last post by:
I need to save my Access 2010 database in 2003 format so that someone can use it that is only running 2003. My database was built using Access 1997 and has been upgraded over the years to 2003, 2007...
3
by: improveit4 | last post by:
I am a High school volunteer who would like to send a email to each contact in my access 2010 table with selected fields from their record. I would like to be able to attach a word doc to this email....
5
by: Katie Howard | last post by:
I have an Access 2010 database and am using the feature of collecting data by email. I’m using the InfoPath form as the means of collecting the data. In general, it works well – but I’ve run into 2...
6
by: mlgmlg | last post by:
Hello, I desperately need help to modify a where condition that was created when I added a button to open a form and find specific data by to display. The form currently opens and displays a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.