Results 1 to 4 of 4
  1. #1
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402

    dlookup problems

    Hi all

    i have a database that creates work tickets which is working really well, the problem i have is this.

    I have a form "Support Form" that collects the computer name in a text field called "text142" when the form opens, this is done by using a module using this code.

    Option Compare Database
    Option Explicit

    Private Declare Function GetComputerName Lib "kernel32" _
    Alias "GetComputerNameA" ( _
    ByVal lpBuffer As String, _


    ByRef nSize As Long) As Long


    Function ComputerName() As String
    Dim stBuff As String * 255
    Dim lAPIResult As Long
    Dim lBuffLen As Long
    lBuffLen = 255
    lAPIResult = GetComputerName(stBuff, lBuffLen)
    If lBuffLen > 0 Then
    ComputerName = Left(stBuff, lBuffLen)
    End If
    End Function


    what i am trying to do is lookup the ID of the computer in the "Asset" table using the name of the PC "AssetName", and put the ID in a text field called "answer"
    all the computers on our network use the naming convention PC-**-** were ** is either a letter or number

    i am using this as my dlookup

    Me.answer = DLookup("[AssetID]", "Asset", "[AssetName]= " & [ComputerName])

    the problem i have is that the look up always give this error

    Runtime Error 2471
    the expression you entered as a query parameter produced this error 'PC'

    any help would be fantastic
    Steve

  2. #2
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi All

    i have managed to get the dlookup to work using this code

    Me.Text14 = DLookup("assetID", "Asset", "AssetName = 'LT-IT-02'")

    me.text14 is the name of the textbox that i want to show the ID of the asset with the name LT-IT-02 this works correctly and returns the value 66 in the text box "me.text14" when i open the form

    if i replace
    Me.Text14 = DLookup("assetID", "Asset", "AssetName = 'LT-IT-02'")
    with
    Me.Text14 = DLookup("assetID", "asset", "AssetName = 'ComputerName'")

    me.text14 is empty when the form loads and i do not get any errors

    any ideas??

    i must be doing something really silly but can't find my error.

    Cheers

    Steve

  3. #3
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    You need quotes around the [ComputerName].

    Me.answer = DLookup("[AssetID]", "Asset", "[AssetName]= '" & [ComputerName] & "'")

  4. #4
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi ifm062010

    Many thanks, that works brilliantly, thank you so much many many thanks

    Steve

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Two Problems
    By IannWard in forum Forms
    Replies: 3
    Last Post: 03-23-2014, 11:23 PM
  2. IIF Problems
    By suverman in forum Queries
    Replies: 3
    Last Post: 05-23-2011, 02:22 AM
  3. Replies: 2
    Last Post: 05-16-2011, 04:11 PM
  4. problems please help
    By stryder09 in forum Access
    Replies: 1
    Last Post: 02-15-2011, 02:24 PM
  5. OLE problems how to fix
    By miziri in forum Access
    Replies: 7
    Last Post: 04-29-2010, 06:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums