If statement

G

Guest

Firstly, I’m not a programmer, but just somebody who find’s this very
interesting.

I’m building a database for a company to control their insurance on their
vehicles. I have two forms, frmNewEntry and frmClaims. All the vehicles are
entered into frmNewEntry and when there is an insurance claim, they put that
into frmClaims.

If I enter the vehicle registration number into frmClaims, I want access to
automatically fill in fields like Model, Make, YearOfFirstRegistration,
DriverName,DriverSurname, DriverInitials. I tried to use an If statement in
the lostfocus event of the field,RegistrationNumber in frmClaims.

It looked something like this:

If Form_frmClaim.RegNo = Form_frmNewEntry.RegistrationNumber Then
Form_frmClaim.InsuredDriverName = Form_frmNewEntry.Surname
End If

Can somebody please help me with this.

Regards

Peet
 
G

Guest

Create a combo box where the user will enter the vehicle registration number,
the row source of the combo will includes all the fields that you want to
display

Select [registration number],Model, Make, YearOfFirstRegistration,
DriverName, DriverSurname, DriverInitials From TableName
==============================================
The column number of the row source start with 0, so Model will be column 1
==============================================
Create fields in the form, in the control source of the text box write
In the modal text box
[ComboName].column(1)
In the Make text box
[ComboName].column(2)
etc
==============================================
Or, on the after update event of the combo, you can write the code
Me.[ModalTextBoxname] = Me.[ComboName].column(1)
Me.[MakeTextBoxname] = Me.[ComboName].column(2
etc
==============================================
It is better then using dlookup on each field, because the user will access
the table only once
==============================================
and you can limit the user to select only exist vehicle numbers
 
G

Guest

Thanx for the help I received. Helped me a lot.

Now I have a second problem. On my one form I have 5 fields.
EmployerRiskFactor, LocalityRiskFactor, DriverRiskFactor, CarTypeRiskFactor
and CompositeRiskFactor. The first four get their values from choices that
the user make in four dropdowns on the form. The last one get its value by
multiplying the values of the first four.

All I did was to type the following in the last textbox
=[EmployerRiskFactor]*[DriverRiskFactor]*[CarTypeRiskFactor]*[LocalityRiskFactor]

It worked very good. My only concern now is to get this textbox to write its
calculated value to the field in the table.

Peet
 
G

Guest

You don't do that, don't save a calculated field that is based on existing
fields, you can always get the value using a query.
Select *,
[EmployerRiskFactor]*[DriverRiskFactor]*[CarTypeRiskFactor]*[LocalityRiskFactor] as CalcField From TableName

Saving a calculated field mean that you need to maintain it all the time,
and if you update one of the fields from the table, the calculated field wont
be updated.
So, for your benefit don't save a calculated field
--
I hope that helped
Good luck


Peet said:
Thanx for the help I received. Helped me a lot.

Now I have a second problem. On my one form I have 5 fields.
EmployerRiskFactor, LocalityRiskFactor, DriverRiskFactor, CarTypeRiskFactor
and CompositeRiskFactor. The first four get their values from choices that
the user make in four dropdowns on the form. The last one get its value by
multiplying the values of the first four.

All I did was to type the following in the last textbox
=[EmployerRiskFactor]*[DriverRiskFactor]*[CarTypeRiskFactor]*[LocalityRiskFactor]

It worked very good. My only concern now is to get this textbox to write its
calculated value to the field in the table.

Peet

Peet said:
Firstly, I’m not a programmer, but just somebody who find’s this very
interesting.

I’m building a database for a company to control their insurance on their
vehicles. I have two forms, frmNewEntry and frmClaims. All the vehicles are
entered into frmNewEntry and when there is an insurance claim, they put that
into frmClaims.

If I enter the vehicle registration number into frmClaims, I want access to
automatically fill in fields like Model, Make, YearOfFirstRegistration,
DriverName,DriverSurname, DriverInitials. I tried to use an If statement in
the lostfocus event of the field,RegistrationNumber in frmClaims.

It looked something like this:

If Form_frmClaim.RegNo = Form_frmNewEntry.RegistrationNumber Then
Form_frmClaim.InsuredDriverName = Form_frmNewEntry.Surname
End If

Can somebody please help me with this.

Regards

Peet
 

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