Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB in MS Access

Posted on 2014-10-12
5
Medium Priority
?
232 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 52

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 52

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 52

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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…
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

916 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