Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922

    Great point Ajax. Good eye.

  2. #17
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    My modifications:
    Code:
        Dim rst As dao.Recordset
        Dim iVal As Integer
        Dim iVal2 As String
        Dim sSQL As String
    
        iVal = Nz(Me.cbointReportID, 0)
    
        iVal2 = Nz(Me.cbovarReportTitle, "")
    
        sSQL = "SELECT *"
        sSQL = sSQL & " FROM dbo_tbl_Custom_Subscription_Subscriptions"
        sSQL = sSQL & " WHERE intReportID = " & iVal & " AND varReportTitle = '" & ConvertQuotesSingle(iVal2) & "'"
        '   Debug.Print sSQL
        Set rst = CurrentDb.OpenRecordset(sSQL)
    
        If Not rst.EOF Then  '<<-- like Ajax suggests
            Me.txtintSubID = rst![intSubscriptionID]
            Me.txtvarExtensionSettingValueList = rst![varExtensionSettingValueList]
            Me.cbobitActiveForNoRecords = rst![bitActiveForNoRecords]
            Me.cbobitActive = rst![bitActive]
            Me.txtdatStartDate = rst![datStartDate]
            Me.txtdatEndDate = rst![datEndDate]
            Me.txtdatAdded = rst![datAdded]
            Me.txtdatModified = rst![datModified]
        Else
            MsgBox "No records to return"
        End If
    
        ' clean up
        rst.Close
        Set rst = Nothing
    Putting the SQL string into a string variable allows you to print the SQL string to the immediate window (using Debug.Print sSQL) to see if the SQL is properly formed. You can copy the SQL from the immediate window and paste it into a new query (SQL view), then execute the query to see if records are returned. One of my most used debugging methods.

    I also use this function to deal with apostrophe's in text:
    Code:
    Function ConvertQuotesSingle(InputVal)
       ConvertQuotesSingle = Replace(InputVal, "'", "''")
    End Function

    One more thing: "iVal" is declared as an Integer, so you cannot assign an empty string to it if Me.cbointReportID is NULL.

    Incorrect:
    iVal = Nz(Me.cbointReportID.Value, "")

    Correct:
    iVal = Nz(Me.cbointReportID, 0)

  3. #18
    AAAndy is offline Advanced Beginner
    Windows 7 64bit Access 2013 32bit
    Join Date
    Aug 2016
    Posts
    68
    That seems to work, I will monitor the issue. Thanks for everyones help.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 0
    Last Post: 07-29-2016, 10:11 PM
  2. Replies: 4
    Last Post: 06-04-2015, 01:07 PM
  3. Replies: 8
    Last Post: 11-12-2010, 10:55 AM
  4. Replies: 17
    Last Post: 03-09-2010, 07:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums