Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 2011
    Posts
    28

    Unanswered: Run-Time Error 2645

    Hi



    Please can anyone help.



    I get the following error when trying to excute the code below



    "Run-Time Error 2645



    Microsoft Access can't find the field '|' referred to in your expression"



    Below is the code



    Private Sub Command111_Click()
    Me.Encrpytion_Password = DLookup("[Password]", "[Tableencryptionpassword]", "[EncryptionID] = " & Nz([EncryptionID], 0))
    End Sub




    I have checked the spelling of the all the fieldnames and they are correct.



    Any help would be much apprecitaed.



    Thanks

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    is the encryption ID a number or a string / text value
    if the later it must be encapsualted by ' or " symbols

    Me.Encrpytion_Password = DLookup("[Password]", "[Tableencryptionpassword]", "[EncryptionID] = '" & Nz([EncryptionID], 0) & "'")

    also check that there is a control or variable for the EncryptionID

    Id also suggest examining the variables in the dlookup when the code breaks.
    either put the cursor over each item and make certain its valid
    OR
    in the immediate window display the data
    eg
    ?EncryptionID
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Sep 2011
    Posts
    28
    Hi Healdem

    Many thanks for your help.

    I have tried your code but get the same error.

    Forgive me but I am a novice to coding. What do you mean by control or variable?

    Thanks

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    in SQL
    a table is comprised of columns
    in Microsoft Access / Office / VB.NET
    a form or report is comprised of controls and variable and constants

    controls are the widget that displays something (could be a picture, a line a value from the database [ie a column from a table], it copuld be a value from a variable or constant)

    a control is unique to a form / report.
    a constant is probably unique to a form or report as you would normally declare them in a form or report or possibly a code module

    the potentail problem is that when you use the form / report wizards they ten to name the controls the same as the underlying column

    so its quite possible in your situation you have two or more things with the same name which the Access runtime has to resolve.


    what values do you get if you type the following into the immediate window whent he code halts execution


    ?"[EncryptionID] = '" & Nz([EncryptionID], 0)

    is EncryptionID when defined in the table a numeric or string / text datatype
    what values do you expect for EncryptionID?
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Aug 2003
    Location
    Cleveland USA
    Posts
    184
    Is [EncryptionID] both the name of your field AND the name of the control on the field? Access names them the same by default, but VBA does not like it. Rename your control to something like lngEncryptionID (just needs to be different) and change your code to:

    Me.Encrpytion_Password = DLookup("[Password]", "[Tableencryptionpassword]", "[EncryptionID] = " & Nz(lngEncryptionID, 0))

  6. #6
    Join Date
    Sep 2011
    Posts
    28
    Hi Lisa

    Thanks for your help.

    Headlem, EncryptionID is an Autonumber, it is a Primary Key
    Last edited by Mohamedk; 10-18-11 at 11:41.

  7. #7
    Join Date
    Sep 2011
    Posts
    28
    Hello

    I have managed to get further now.

    I dont get any coding errors now when I press the command button. However when clicking on the button it does not seem to be populating the field with a value from the table.

    Below is the code

    Private Sub Command112_Click()
    Me.lngEncryption_Password = DLookup("Password", "[tblpasswords]", "Password = '" & Nz(EncryptionID, 0) & "'")
    End Sub

    Again, any help will be much appreciated.

    Thanks

  8. #8
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so check your SQL
    is there a row in the table that matches the requirement

    for now I'd suggest that you hard code some values that you know work

    right now I / we / you do not know if the problem is you data, your dlookup or your values

    so first off check what values are in tblpasswords
    find a known good value
    supply that value to the dlookup
    Me.lngEncryption_Password = DLookup("Password", "[tblpasswords]", "Password = '<myknowngoodpassword>'")

    if that works then it proves the dlookup is fine, the rest of thec ode is fine

    if it fails then it suggests there is a problem with either the dlookup or your data

    as suggested before make certain your dlookup code is correct. put a watch on the statement
    of display it using a message box
    msgbox("Password = '" & Nz(EncryptionID, 0) & "'")

    What datatype is Me.lngEncryption_Password
    if you try to assign the value of a string / text column to a numeric column it may not work out.
    I'd rather be riding on the Tiger 800 or the Norton

  9. #9
    Join Date
    Sep 2011
    Posts
    28
    Once again tahnks for your help healdem

    I'm almost there. I have used your code. I am now able to populate a value into the field from tblpasswords. but when i add a new record into the database and press the command button it always chooses the top value from tblpasswords. I would like it to choose the next value.

    Any ideas how?

    My code is below


    Private Sub Command111_Click()
    Me.lngEncrpytion_Password = DLookup("[Password]", "[tblpasswords]", "EncryptionID = Password = '" < myknowngoodpassword > "'")
    End Sub

    Thanks

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •