Solved

VB in MS Access

Posted on 2014-10-12
5
219 Views
Last Modified: 2014-10-13
We have a module that reads records from 1 table and adds them to others.  The data type on a field changed from numeric to text and we now get a data type mismatch error.  I've confirmed all the tables are defined correctly.  There must be an issue with the syntax of the code.  The If statement below is where it fails

 Do Until .EOF
            Set rstApplicant = db.OpenRecordset("Charity Applicant", dbOpenDynaset)
            If DCount("*", "Charity Applicant", "[MRN] = " & ![MRN]) = 0 Then...

I appreciate your help!
0
Comment
Question by:motherm
  • 3
  • 2
5 Comments
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 40375747
Try with:

 If DCount("*", "Charity Applicant", "[MRN] = '" & ![MRN] & "'") = 0 Then...

/gustav
0
 

Author Closing Comment

by:motherm
ID: 40375805
Thank you for your solution.  

 Now I get a data type mismatch on the following code:  
MRN is text and application no is numeric.  When I tried putting quotes around MRN it failed to compile.


  If boaddapplication = False Then
                               rstAccount.Fields("Application No") = _
                            (Nz(DMax("[Application No]", "[Charity Applicant Accounts]", "[MRN] = " & ![MRN]), 0) + 1)
                   Else
                         rstAccount.Fields("Application No") = _
                            (Nz(DMax("[Application No]", "[Charity Applicant Accounts]", "[MRN] = " & ![MRN]), 0))
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 40375818
I guess they should read:

     Val(Nz(DMax("[Application No]", "[Charity Applicant Accounts]", "[MRN] = '" & ![MRN] & "'"), "0")) + 1

and:
     Val(Nz(DMax("[Application No]", "[Charity Applicant Accounts]", "[MRN] = '" & ![MRN] & "'"), "0"))

/gustav
0
 

Author Comment

by:motherm
ID: 40375830
Great!  Thank you again!  Hopefully, the last issue...

As the code executes further I get a data type conversion error, see below.  It stops on the account number which is defined as numeric.

           If Not boDoNotContinue Then
                If DCount("*", "Charity Applicant Accounts", "[Acct No] = " & ![Acct No]) > 0 Then
                    udfReportOutput ![MRN], ![Acct No], 2
                Else
                    Set rstAccount = db.OpenRecordset("Charity Applicant Accounts", dbOpenDynaset)
                    rstAccount.AddNew
                        rstAccount.Fields("MRN") = ![MRN]
                   If boaddapplication = False Then
                               rstAccount.Fields("Application No") = _
                    Val(Nz(DMax("[Application No]", "[Charity Applicant Accounts]", "[MRN] = '" & ![MRN] & "'"), "0")) + 1
            '    (Nz(DMax("[Application No]", "[Charity Applicant Accounts]", "[MRN] = '" & ![MRN] & "'"), 0) + 1)
           
                       
                   Else
                         rstAccount.Fields("Application No") = _
                           Val(Nz(DMax("[Application No]", "[Charity Applicant Accounts]", "[MRN] = '" & ![MRN] & "'"), "0"))
                    '        (Nz(DMax("[Application No]", "[Charity Applicant Accounts]", "[MRN] = '" & ![MRN] & "'"), 0))
                   End If
                        rstAccount.Fields("Acct No") = ![Acct No]             <=======     Debugger stops here
                        rstAccount.Fields("Account Bal") = ![Account Bal]
                        rstAccount.Fields("Adm Date") = ![Adm Date]
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 40376524
Hard to tell, but probably ![Acct No] is Null
Insert a debug line and watch:

Debug.Print "Acct No:", ![Acct No]
rstAccount.Fields("Acct No") = ![Acct No]             <=======     Debugger stops here

/gustav
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
This video teaches viewers about errors in exception handling.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

813 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now