carrying down values to a new record

H

Heidi

I have two fields in a form, RptType (which is either 'P' for positive or 'N'
for negative), and I have a field called 'Port', which may (or may not) be
populated when a report is positive. I have used the following code to carry
down values entered in a previous record:

Me!Port.DefaultValue = Chr(34) & Me!Port & Chr(34)

But, if I have a record with no "port" value, this code appears to bring
down two double quotes (""). However, I also want to include the following
validation:

If Me.RptType = "N" And IsNull(Me.Port) = False Then
MsgBox "Erase port if this is a negative report", vbOKOnly
Cancel = True
Me.Port.SetFocus

However, when entering a RptType of 'N', this validation code is set off
because (I think) 'Port' is not null, it is acutally "". Is there a better
way to carry down values from one record to the next?

Heidi
 
O

Ofer

Try this

If Me.RptType = "N" And not IsNull(Me.Port) And Me.Port <> "" Then
MsgBox "Erase port if this is a negative report", vbOKOnly
Cancel = True
Me.Port.SetFocus
 
D

David C. Holley

Sounds like you need to test the value BEFORE setting the .DefaultValue
property as in...

If Me.RptType = "N" or Me.RptType = "P" then
Me!port.defaultValue = Chr(34) & Me!Port & Chr(34)
else
Me!port.defaultValue = ""
end if

I added the = "" to clear out any defaultValues already set.
 

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