date variable

  • Thread starter Thread starter G deady via AccessMonster.com
  • Start date Start date
G

G deady via AccessMonster.com

I am trying to create a date variable in a case statement. I want to use
DLookup to pull a date from a date from another and pass it to a unbound
textbox to be used in a date calculation. I have to use a variable because
a textbox will only accept text. I keep getting a Type 13 mismatch error on
dlookup line when I fire the code. Here is my code::
------------
Private Sub Combo62_AfterUpdate()
Select Case Me.Combo62
Dim strFrm As String
Dim dob As Date
Case "Auto Accidents"
strFrm = "frm_AutoAccidents"

If MsgBox("Please review this form to make sure all data is correct. Are
you certain you wish to save this record?", vbQuestion + vbYesNo) = vbNo
Then
DoCmd.CancelEvent
Else

'save pending edits
DoCmd.RunCommand acCmdSaveRecord
strParameters = Me.SCVClientID & ";"
strParameters = strParameters & Me.SCVFileNo & ";"
strParameters = strParameters & Me.txt36 & ";"
strParameters = strParameters & Me.txt38 & ";"
strParameters = strParameters & Me.txt40 & ";"
strParameters = strParameters & Me.txt42 & ";"
dob = DLookup("Birthdate", "tbl_clientinfo", "ClientID = " & Me.SCVClientID)
& _
"#"
Can someone tell me what the correct dlookup statement should be?
 
Sorry, I don't see what the problem is. This should work:
Me!txtDOB = DLookup("Birthdate", "tbl_clientinfo", "ClientID = " &
Me.SCVClientID)

....unless ClientID is a string, in which case, it should be:
Me!txtDOB = DLookup("Birthdate", "tbl_clientinfo", "ClientID = """ &
Me.SCVClientID & """")

But if Birthdate is likely to be null:
Me!txtDOB = Nz(DLookup("Birthdate", "tbl_clientinfo", "ClientID = " &
Me.SCVClientID), "")
...or where ClientID is a string...
Me!txtDOB = Nz(DLookup("Birthdate", "tbl_clientinfo", "ClientID = """ &
Me.SCVClientID & """"), "")

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html
 
Back
Top