Solved

VB in MS Access

Posted on 2014-10-12
5
209 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
Comment Utility
Try with:

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

/gustav
0
 

Author Closing Comment

by:motherm
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

762 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

11 Experts available now in Live!

Get 1:1 Help Now