Rabu, 30 Desember 2015

Re: [MS_AccessPros] If IsNull(OptionDate)

 

John-
I'll do it today and let you know.,Thanks a lot.
Best Regards,
Kevin



发自我的小米手机
在 "John Viescas JohnV@msn.com [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com>,2015年12月31日 上午1:16写道:

 

Kevin-


Open your code in the VB Editor and put a halt on the If statement by clicking the margin to the left.  You should see a red dot appear to indicate it will halt at that point.

Run your app and do whatever is necessary to run this code.  It should stop on the If statement and display the VB Editor and your code.  Go to the Immediate Window and type:

?Me.OptionDate

.. and press Enter.

Tell me what you see.  Click the red dot to clear the halt and click the Run button to let your code finish.

John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
SQL Queries for Mere Mortals 
(Paris, France)



On Dec 30, 2015, at 5:24 PM, 'zhaoliqingoffice@163.com' zhaoliqingoffice@163.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:


John-
I tried what you suggested. it still won't work. "OptionDate" is truly a date value. 
Best Regards,
Kevin

 
Date: 2015-12-31 00:14
Subject: Re: [MS_AccessPros] If IsNull(OptionDate)
 

Kevin-


Is OptionDate a control on the current form?  If so, you should be using Me.  Also, it's better to use VBA If rather than call the function - like this:

If IsNull(Me.OptionDate) Then
    strRpt = "rptHotelBookingAskOption"
    strPrefix = "Asking for Option for group: "
Else
    strRpt = "rptHotelBookingExtendOption"
    strPrefix = "Asking for Extending the Option for the group: "
End If

If OptionDate is truly a date/time value, then it will be Null when "blank" or has no value.

John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
SQL Queries for Mere Mortals 
(Paris, France)

On Dec 30, 2015, at 5:06 PM, 'zhaoliqingoffice@163.com' zhaoliqingoffice@163.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

John-
It seems that IsNull won't work for date type. 
Best Regards,
Kevin

On Dec 30, 2015, at 5:04 PM, 'zhaoliqingoffice@163.com' zhaoliqingoffice@163.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

John-
I am using this in vb:

On Error GoTo ErrHandle

Dim strRpt As String
Dim strPrefix As String
Dim strEmailAddress As String
Dim strSubject As String


strRpt = IIf(IsNull(OptionDate),"rptHotelBookingAskOption","rptHotelBookingExtendOption")

strPrefix = IIf(IsNull(OptionDate),"Asking for Option for group: ","Asking for Extending the Option for group: ")

strEmailAddress = ELookup("HotelContactEmail", "tblHotelContact", "HotelID=" & Me.HotelID, "RecentContact ASC")

strSubject = strPrefix & "-" & IIf(IsNull(HotelBookingCode), Me.Parent.GroupCode & "-" & HotelBookingID, Me.Parent.GroupCode & "-" & _
HotelBookingID & " (Reference: " & HotelBookingCode & ")") & " From " & ELookup("CompanyEnglishName", "tblCompany", "CompanyID=" & 1)

    If vbYes = MsgBox("Click Yes to send. " & _
        " Click No to edit.", vbQuestion + vbYesNo + vbDefaultButton2) Then

    DoCmd.OpenReport strRpt, acViewPreview, , "HotelBookingID = " & Me.HotelBookingID, acHidden
    SendReportHTML strRpt, strEmailAddress, strSubject, "Send", ""
    DoCmd.Close acReport, strRpt, acSaveNo
    
    Else
    DoCmd.OpenReport strRpt, acViewPreview, , "HotelBookingID = " & Me.HotelBookingID, acHidden
    SendReportHTML strRpt, strEmailAddress, strSubject, "Display", ""
    DoCmd.Close acReport, strRpt, acSaveNo

    End If

ErrExit:
    Exit Sub
    
ErrHandle:
    Resume ErrExit

Best Regards,
Kevin


 
Date: 2015-12-31 00:02
Subject: Re: [MS_AccessPros] If IsNull(OptionDate)
 

Kevin-


Where are you using this - in a query?

Only obvious thing is to put brackets around the field name:

IIf(IsNull([OptionDate]),"rptHotelBookingAskOption","rptHotelBookingExtendOption")

John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
SQL Queries for Mere Mortals 
(Paris, France)



On Dec 30, 2015, at 4:50 PM, 'zhaoliqingoffice@163.com' zhaoliqingoffice@163.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:


Dear All,
Please check this code: IIf(IsNull(OptionDate),"rptHotelBookingAskOption","rptHotelBookingExtendOption")
My problem is: if OptionDate is null, the the result won't be "rptHotelBookingAskOption". What's wrong with this code? Thanks.
Best Regards,
Kevin







__._,_.___

Posted by: zhaoliqingoffice <zhaoliqingoffice@163.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (11)

.

__,_._,___

Tidak ada komentar:

Posting Komentar