Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / January 2006

Tip: Looking for answers? Try searching our database.

data types

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bob Wickham - 17 Jan 2006 23:39 GMT
Hi,
I have the following code created with the assistance of Steve Schapel.
When this code was written, the data type of the fields, tblLoan.LoanNo
and tblCommission.LoanNo was Number.
As I dont have to do any calculations on these fields and to solve
another problem associated with importing the data from Excel I have
changed the data type to Text.
But now the code doesn't work, stating there has been a "Data type
mismatch in Criteria Expression".
I'm assuming I need to convert the references to LoanNo to a String but
I'm not sure just where to do that.

Private Sub cmdCommissionMissing_Click()
On Error GoTo Err_cmdCommissionMissing_Click

  Dim dbs As Database
  Dim rstLoans As DAO.Recordset
  Dim rstMissed As DAO.Recordset
  Dim strSql As String

  Set dbs = CurrentDb

' call the function DeleteAll("tblMissingCommissionReport")

Call DeleteAll("tblMissingCommissionReport")

  Set rstLoans = dbs.OpenRecordset("SELECT tblLoan.LoanNo,
tblLoan.LoanStartDate FROM tblLoan" & _
  " INNER JOIN tblCommission ON tblLoan.LoanNo = tblCommission.LoanNo
WHERE tblCommission.CommissionType=1")

  Do Until rstLoans.EOF
    Set rstMissed = dbs.OpenRecordset("SELECT DISTINCT [MonthYear]" & _
                   " FROM tblDate" & _
                   " WHERE [MonthYear] > " &
CLng(rstLoans!LoanStartDate) & _
                   " AND [MonthYear] < DateSerial(Year(Date()),
Month(Date()), 1)" & _
                   " AND Format([MonthYear],'mmmm,yyyy')" & _
                   " Not In (SELECT Format ([PaymentDate],'mmmm,yyyy')" & _
                              " FROM tblCommission" & _
                              " WHERE LoanNo =" & rstLoans!LoanNo & ")")

     Do Until rstMissed.EOF
          strSql = "INSERT INTO tblMissingCommissionReport (
LoanNumber, TheDate )" & _
          " VALUES ( " & rstLoans!LoanNo & ", " &
CLng(rstMissed!MonthYear) & " )"
          dbs.Execute strSql, dbFailOnError
          rstMissed.MoveNext
     Loop
     rstMissed.Close
     rstLoans.MoveNext
  Loop
  rstLoans.Close
  Set rstMissed = Nothing
  Set rstLoans = Nothing
  Set dbs = Nothing

  ' call the sub RunMcrMissingCommissionReportPrintPreview()

  Call RunMcrMissingCommissionReportPrintPreview

Exit_cmdCommissionMissing_Click:
    Exit Sub

Err_cmdCommissionMissing_Click:
    MsgBox Err.Description
    Resume Exit_cmdCommissionMissing_Click

End Sub

Thanks,

Bob Wickham
Dirk - 18 Jan 2006 09:42 GMT
Since the LoanNo is a String now you will have to quote values in where
clauses:

Try canging:

Set rstMissed = dbs.OpenRecordset("SELECT DISTINCT [MonthYear]" & _
" FROM tblDate" & _
" WHERE [MonthYear] > " &
CLng(rstLoans!LoanStartDate) & _
" AND [MonthYear] < DateSerial(Year(Date()),
Month(Date()), 1)" & _
" AND Format([MonthYear],'mmmm,yyyy')" & _
" Not In (SELECT Format ([PaymentDate],'mmmm,yyyy')" & _
" FROM tblCommission" & _
" WHERE LoanNo =" & rstLoans!LoanNo & ")")

Change last line to:

" WHERE LoanNo = '" & rstLoans!LoanNo & "')")

Please note the use of single quotation marks.
Please let me know if that worked.

Regards,

Dirk Louwers

> Hi,
> I have the following code created with the assistance of Steve Schapel.
[quoted text clipped - 71 lines]
>
> Bob Wickham
Bob Wickham - 18 Jan 2006 21:32 GMT
> Since the LoanNo is a String now you will have to quote values in where
> clauses:
[quoted text clipped - 22 lines]
>
> Dirk Louwers

 Hi Dirk,

Yes, that works.
I actually withdrew my post because I thought I found another way around
it, but I didn't.

You see, I'm linking to an Excel spreadsheet. In that spreadsheet the
LoanNo field is a Number. When I append those records to an Access table
where the LoanNo field is Text it "magically" becomes Text. I dont
understand how it does this and it is the source of some confusion.

But your solution is so simple and most importantly, it works.

Thankyou

Bob Wickham
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.