my autofill won't work ???

B

_Bigred

I am trying to setup a db so when you open

the Discipline Manager Form (based on tblDisciplineLog)

you enter the NumberID which is a Inmate Number (each inmate has a unique
number that never changes while they are incarcerated in the state) I wan't
to automatically fill the remaining fields LastName, FirstName, RoomID from
the data from tblMaster that corresponds to the NumberID

I tried to create a form based on the [tblDisciplineLog] and then set the
NumberID field on the form to do a OnExit code to update the remaining
fields I used the below code:


Sub NumberID_OnExit(Cancel As Integer)
Dim varLastName, varFirstName As Variant
varLastName = DLookup("LastName", "tblMaster", "NumberID =[NumberID] ")
varFirstName = DLookup("FirstName", "tblMaster", "NumberID =[NumberID] ")
If (Not IsNull(varLastName)) Then Me![LastName] = varLastName
If (Not IsNull(varFirstName)) Then Me![FirstName] = varFirstName
End Sub

(Just a quick thought do I need to set a relationship from the table menu
between the NumberID in both tblMaster and tblDisciplineLog to make the code
work?)

Any ideas of what I'm doing wrong or how to fix it would be appreciated.
_Bigred
 
I

Ivan Grozney

BigRed,

Try changing your code to:

varLastName = DLookup("LastName", "tblMaster", "NumberID =" &
Forms![<formname>]![NumberID] ")
varFirstName = DLookup("FirstName", "tblMaster", "NumberID =" &
Forms![<formname>]![NumberID] )

Have you thought about a Combo Box for the Inmate Number? Just a thought
'cause if anyone is half as dyslexic as I am ...

hth
Vanya
 
B

_Bigred

thanks Vanya I will tryout your comments.

Thanks,
_Bigred


Ivan Grozney said:
BigRed,

Try changing your code to:

varLastName = DLookup("LastName", "tblMaster", "NumberID =" &
Forms![<formname>]![NumberID] ")
varFirstName = DLookup("FirstName", "tblMaster", "NumberID =" &
Forms![<formname>]![NumberID] )

Have you thought about a Combo Box for the Inmate Number? Just a thought
'cause if anyone is half as dyslexic as I am ...

hth
Vanya

_Bigred said:
I am trying to setup a db so when you open

the Discipline Manager Form (based on tblDisciplineLog)

you enter the NumberID which is a Inmate Number (each inmate has a unique
number that never changes while they are incarcerated in the state) I
wan't
to automatically fill the remaining fields LastName, FirstName, RoomID
from
the data from tblMaster that corresponds to the NumberID

I tried to create a form based on the [tblDisciplineLog] and then set the
NumberID field on the form to do a OnExit code to update the remaining
fields I used the below code:


Sub NumberID_OnExit(Cancel As Integer)
Dim varLastName, varFirstName As Variant
varLastName = DLookup("LastName", "tblMaster", "NumberID =[NumberID] ")
varFirstName = DLookup("FirstName", "tblMaster", "NumberID =[NumberID] ")
If (Not IsNull(varLastName)) Then Me![LastName] = varLastName
If (Not IsNull(varFirstName)) Then Me![FirstName] = varFirstName
End Sub

(Just a quick thought do I need to set a relationship from the table menu
between the NumberID in both tblMaster and tblDisciplineLog to make the
code
work?)

Any ideas of what I'm doing wrong or how to fix it would be appreciated.
_Bigred
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top