Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB in MS Access

Posted on 2014-10-12
5
Medium Priority
?
230 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 51

Accepted Solution

by:
Gustav Brock earned 2000 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 51

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 51

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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

721 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