If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Problem with Dlookup function

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-02-12, 07:24
jahydc91 jahydc91 is offline
Registered User
 
Join Date: Feb 2012
Posts: 1
Problem with Dlookup function

Hi,

This is my first time posting and I'm fairly new to Access and VBA. I'm working on a simple after update function and I can't get the dlookup to work with a date field that its taking from a form. Here's my code so far:

Code:
Private Sub txtCDate_AfterUpdate()
 
    If IsNull(DLookup([cheque_date], "Cheque_Details", "[Cheque_Date] =" & Forms![PAS].[txtCDate])) Then

        With DoCmd
            .SetWarnings False
            .OpenQuery (qryEmployeeInfo)
            .SetWarnings True
        End With
          
    Else
            
        With DoCmd
            .SetWarnings False
            .OpenQuery (qryChequeDetails)
            .SetWarnings True
        End With
    
    End If

End Sub

It might have something to do with the format that I have my date in as it's in dd/mm/yyyy format and not standard US date format, but that's the format it needs to be in for storage in my database.

Any advice anyone may have would be great

Thanks,
Jahyd
Reply With Quote
  #2 (permalink)  
Old 02-02-12, 07:56
Sinndho Sinndho is offline
Registered User
 
Join Date: Mar 2009
Posts: 3,446
Provided that "cheque_date" is the name of a column (field) in the table (or query) "Cheque_Details", you can try:
Code:
If IsNull(DLookup("cheque_date", "Cheque_Details", "[Cheque_Date] = #" & Format(Me.txtCDate.Value, "mm/dd/yyyy") & "#")) Then
__________________
Have a nice day!
Reply With Quote
  #3 (permalink)  
Old 02-02-12, 07:59
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
Access/JET is US centric so it should be mm/dd/yyyy or at a pinch ISO format yyyy/mm/dd
also there is an expectation that date literals should be encapsualted with #

Code:
If IsNull(DLookup([cheque_date], "Cheque_Details", "[Cheque_Date] = " & format(Forms![PAS].[txtCDate],"#yyyy/mm/dd#")) Then
or
Code:
If IsNull(DLookup([cheque_date], "Cheque_Details", "[Cheque_Date] = " & format(Forms![PAS].[txtCDate],"#mm/dd/yyyy#")) Then
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #4 (permalink)  
Old 02-02-12, 16:56
Missinglinq Missinglinq is offline
Registered User
 
Join Date: Jun 2005
Location: Richmond, Virginia USA
Posts: 1,702
And since you're stuck in that universe where Dates are not in the US Format, you'd better bookmark Allen Browne's excellent article on the subject:

Microsoft Access tips: International Dates in Access

Linq ;0)>
__________________
Hope this helps!

The Devil's in the Details!!

All posts/responses based on Access 2000/2003
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On