Question help Dlookup function

terminator88

New member
Local time
Today, 11:57
Joined
Nov 15, 2012
Messages
5
hey,ia have a simply access Table1 like this:

Nr Simbol (Nr field and Simbol are formatted Text data)
1 a
2 b
3 c

i have created a form for this table,and i want this:when i put "1" in Nr box in the form,automatically form show me "a" in simbol box.
I write this code in VB:

Private Sub Nr_AfterUpdate()
Simbol = DLookup("Simbol", "Table1", "Nr= " & Nr)
End Sub

But when i open the form,when i put 1 in Nr box form doesent work,it say:
run-time error 3464,data type mismatch in criteria experssion
i read some smiliar post in this forum but nothing :(
 
If Nr is text then you'll need to use it in quotes thus

Code:
Private Sub Nr_AfterUpdate()
Simbol = DLookup("Simbol", "Table1", "Nr= '" & Nr & "'")
End Sub
 
You write a Form, and you want to enter 1 (it means you want to enter a
new record), wherefrom you want to see "a", (you have no record in your
table). You can use an IF function for this (not Dlookup).

If Me.Nr = 1 Then
Me.Simbol = "a"
'and so on.
End if
 
Last edited:
thnx man,i use 2days searching for this problem,i have an other question:
when i put the 1 in Nr-box.i need to push Enter form Keyboard to refresh the data in Simbol-Box,how can do this automatically without pushing Enter
 
Are you sure you don't want to use a Combo Box?

This is the dropdown list control that allows you to pick values from a list. However what it can also do is to save one value to the table of your form but show a different value on your form that is you pick 'a' from the list but it stores 1 in your table.

If you drop a Combo Box on your form it will bring up the Combo Box wizard. From what you say you might want to try this.

1) Choose the "I want the combo box to get the values from another table ..." option.

2) Choose Table 1 as the table you get the value for your combo box from.

3) Choose both Nr and Simbol to be included in your combo box.

4) You could optionally chose to sort the entries by Simbol A -> Z

5) Accept the option to Hide key column, this will be the value stored in the table of the form.

6) Choose a Label for your combo box 'Simbol' (or Symbol, which is how we spell it in the UK)

7) Click Finish

I have attached a database with a form called frmComboBoxTest with a combo box on it, built using the steps above, to show you what I mean.
 

Attachments

Users who are viewing this thread

Back
Top Bottom