if textbox entry is blank, add "unknown" automatically

G

Guest

hi

I have 3 tables
Vehicles (PK VRM)
Drivers (PK Driver ID)
and VehiclesDrivers (PKs VRM and DriverID)

I have a main form Drivers and a subform DriversVehicles showing drivers
related to the vehicle.

I have a DOB field in the subform. When adding or amending records, if the
user doesn't enter a value, how can I automatically add the value "unknown"
to the field in the underlying Drivers table, then have this show in the DOB
field in the form? (Before Update event?)
I currently have the input mask 00/00/00;0;_ on both the form textbox and
the table field. Does this input mask still allow other values (ie "unkown")
to be written by code, or does an input mask prevent entry from both the
keyboard and by an automatic "write" from code?

If an automatic "write" is forbidden, I guess I'll have to take the input
mask off, at the expense of permitting inaccurate data entry in the DOB
field. Or is there another way to do this?

TIA
rich
 
A

Arvin Meyer [MVP]

It's not the input mask that will present the biggest problem, it's the
datatype of the underlying field. You cannot put text in a date field. So
you will either need to use a default date, change the field to a text
datatype (which means you'll need to convert dates back to do calculations,
and you'll need error handling for the non-date entries).

So assuming you take the input mask off and change the datatype of the
underlying field, some aircode might look like this:

Sub Form_BeforeUpdate(Cancel As Integer)
If Len([FieldName] & vbNullString) = 0 Then
Me.FieldName = "unknown"
End If
End Sub
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 

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