By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,453 Members | 3,183 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,453 IT Pros & Developers. It's quick & easy.

DoCmd Open Form

P: 55
After displaying search results, I want to be able to double click the identity number field and then the input form SubmissionDetails becomes the display form for the results of the data matching value of the selected identity number. With my code below I get a data type mismatch error. Please help me.......
Expand|Select|Wrap|Line Numbers
  1. Private Sub IdentityNumber_Click()
  2. On Error GoTo IdentityNumber_Click_Err
  3.  
  4.     On Error Resume Next
  5.     If (Form.Dirty) Then
  6.         DoCmd.RunCommand acCmdSaveRecord
  7.     End If
  8.     If (MacroError.Number <> 0) Then
  9.         Beep
  10.         MsgBox MacroError.Description, vbOKOnly, ""
  11.         Exit Sub
  12.     End If
  13.     On Error GoTo 0
  14.     DoCmd.OpenForm "SubmissionDetails", acNormal, , "[IdentityNumber]=" & IdentityNumber, , acDialog
  15.     'DoCmd.OpenForm "SubmissionDetails", acNormal, "", "[IdentityNumber]=" & IIf(Nz(IdentityNumber.Value) = vbNullString, "No value.", IdentityNumber.Value & "."), , acDialog
  16.  
  17.     'IIf(Nz(IdentityNumber.Value) = vbNullString, "No value.", "Value is " & IdentityNumber.Value & ".")
  18.  
  19.     If (Not IsNull(IdentityNumber)) Then
  20.         TempVars.Add "CurrentID", "[IdentityNumber]"
  21.     End If
  22.     If (IsNull(IdentityNumber)) Then
  23.         TempVars.Add "CurrentID", "Nz(DMax(""[IdentityNumber]"",[Form].[RecordSource]),0)"
  24.     End If
  25.     DoCmd.Requery ""
  26.     DoCmd.SearchForRecord , "", acFirst, "[IdentityNumber]=" & TempVars!CurrentID
  27.     TempVars.Remove "CurrentID"
  28.  
  29.  
  30. IdentityNumber_Click_Exit:
  31.     Exit Sub
  32.  
  33. IdentityNumber_Click_Err:
  34.     MsgBox Error$
  35.     Resume IdentityNumber_Click_Exit
  36.  
  37. End Sub
Feb 16 '09 #1
Share this Question
Share on Google+
5 Replies


NeoPa
Expert Mod 15k+
P: 31,494
As a full member now, you should know that we expect your code to be posted in [code] tags (See How to Ask a Question).
This makes it easier for our Experts to read and understand it.

Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use the tags in future.

Administrator.

PS. Please indicate (at least) which line the reported error occurs on.
Feb 16 '09 #2

P: 55
Thank you NeoPa. I tried to do so but my window would allow me to insert tags so I ended up sending without them. Anyway just figured out where the problem was. Instead of making the IdentityNumber on the right a string, I had made it a number. So I just put some quotes around it and it was solved.
Feb 16 '09 #3

missinglinq
Expert 2.5K+
P: 3,532
My guess is that [IdentityNumber] is defined in your table as Text, which it should be, so your Where clause

"[IdentityNumber]=" & IdentityNumber

needs to be

"[IdentityNumber]= '" & Me.IdentityNumber & "'"

Linq ;0)>
Feb 16 '09 #4

P: 55
Thanks missinglinq,

I realised that that was the problem. Thanks for the reply.
Feb 16 '09 #5

NeoPa
Expert Mod 15k+
P: 31,494
@Lebbsy
No worries then. Maybe this will help :

Tags are done as matching pairs where the opening one is surrounded by [...] and the closing one by [/...]. A set of buttons is available for ease of use in the Standard Editor (Not the Basic Editor). The one for the [ CODE ] tags has a hash (#) on it. You can choose which editor to use in your profile options (Look near the bottom of the page).
Feb 16 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.