0
votes

Hello i've a little problem with my VBA code i'm trying to select the right gps number (double) which matches to the string Name in table tblpersonal and the string in the textbox tabletbesitzerbox. The GPS number should be displayed in the textbox fkgps:

Private Sub SP_Besitzersuche_Click()

    DoCmd.OpenForm "F-Tablet-Hinzufuegen-Neu"
    Dim Sim As Double

    Sim = Nz(DLookup("[GPS]", _
        "tblPersonal", _
        "Name = " & Forms![F-Tablet-Hinzufuegen-Neu]![tabletbesitzerbox]), "")


   FKGPS.Value = Sim

End Sub

The error shows me: Syntaxerror (missing Operation) in query expression 'Name = XY' I'm thankful for every help :)

1

1 Answers

2
votes

String parameters must be enclosed in quotes. When building the criteria in VBA, it is easiest to use single quotes:

Sim = Nz(DLookup("[GPS]", _
    "tblPersonal", _
    "Name = '" & Forms![F-Tablet-Hinzufuegen-Neu]![tabletbesitzerbox] & "'"), 0)