0

I cannot seem to get the following code to run. I appear to be having an issue with using sHostName in my Dlookup statement. What am I doing wrong?

Dim sHostName, LNum As String
sHostName = Environ$("computername")
LNum = DLookup("LineNumber", "tblLineNumber", "ComputerName = sHostName")
Warcupine
  • 4,460
  • 3
  • 15
  • 24
  • Does this answer your question? [MS Access DLookUp using variables](https://stackoverflow.com/questions/19493863/ms-access-dlookup-using-variables) – Warcupine Jun 14 '21 at 14:45
  • Note that `sHostName` has not been declared as a string, but rather a variant - you need to implicitly state the type = `Dim sHostName As String, LNum As String`, – Applecore Jun 14 '21 at 14:58

1 Answers1

0

You need to concatenate the value of the sHostName variable.

DLookup("LineNumber", "tblLineNumber", "ComputerName = '" & sHostName & "'")
Kostas K.
  • 8,293
  • 2
  • 22
  • 28