Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disabling fields 1

Status
Not open for further replies.

ChrisTheAncient

Technical User
Dec 22, 2002
169
GB

I am having a really stupid couple of hours here!

I have an input form for customer details. The form is a cloned recordset.

I wish to make it that a field cannot be used, added to or whatever if the previous field has no entry. (So there can be no Address2 entry if there has been no Address1 entry)

All sorts of combinations and ideas have been tried, and I know it should be darned simple. But after a couple of hours going round in never ending loops, I'm in extremely fed up and dense mode!

Please put me out of my misery.

TIA

Chris

*************************************
OK, I'm stoopid. But I'm good at it!
*************************************
 

p.s. I might not see any replies straight away - I'm about to have my dinner

Chris

*************************************
OK, I'm stoopid. But I'm good at it!
*************************************
 
Hay ChrisTheAncient . . . .

Are you saying you want data entry to follow a specific set order?

cal.gif
See Ya! . . . . . .
 

I'm happy with the data order as it stands.

The final way the eventual reports are being planned, with Address1 and Address2 fields available, I will have a less than ideal presentation if someone accidentally misses out Address1 and goes straight to Address2. The way the report is coming, I can't use shrink or grow properties to 'hide' blank fields because of the way that can affect other data.

To avoid this, I would like to make it that it is impossible to fill in Address2 (or at least an error message pops up) unless Address1 has something in it.

I have used the OnChange property to successfully detect that Address2 has an entry started, but can't seem to make it recognise that there is no data in Address1.

Hope that makes sense.

Chris

*************************************
OK, I'm stoopid. But I'm good at it!
*************************************
 
OK ChrisTheAncient . . . .

Had to give your logic a little thought, espcially as far as the report is concerned. There's alot I can say. But I'll stick to what your lookin for. The following should fit you needs! In the [blue]On Enter[/blue] event of Address2, add the following code:
Code:
[blue]   If Me.NewRecord And IsNull(Me![purple]Address1Name[/purple]) Then
      Me![purple]Address1Name[/purple].SetFocus
   End If[/blue]
The code puts the focus back in Address1 [blue]if its a new record & Address1 is empty[/blue]. If you like you can add an MsgBox function in the If statement if you like.

cal.gif
See Ya! . . . . . .
 

TheAceMan1

Great! Sorted and now adding various twiddles.

I think it was the NewRecord bit that must have been the pitfall that I missed.


Sorry for the delay in response - I'm on UK time and I went to bed just after my last response.

A star for you, Sir, you deserve it!

Many thanks

Chris


*************************************
OK, I'm stoopid. But I'm good at it!
*************************************
 

In case anyone else has been following this, my final code comes out as:
Code:
[COLOR=blue]Private Sub Address2_Change()

    If Me.NewRecord And IsNull(Me!Address1) Then
        Me!Address1.SetFocus
        MsgBox "You can not have a null entry in Address 1 if you need an entry here!"
        Address2 = ""
   End If
   
End Sub
[/color]
My thanks to all lurkers who tried.

Chris

*************************************
OK, I'm stoopid. But I'm good at it!
*************************************
 

Even better!

Made

Address2 = ""

into

Address2 = Null

Dammit, I'm learning a lot of good stuff with the help of this forum!

*************************************
OK, I'm stoopid. But I'm good at it!
*************************************
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top