Solved

VB in MS Access

Posted on 2014-10-12
5
220 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
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.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
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.

821 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