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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cursor Control 1

Status
Not open for further replies.

CarolOB

Programmer
Sep 6, 2001
36
US
I was unable to find a FAQ in the archives for this problem. I apologize if someone has already solved this problem in the past:

I'm new to Access/VB and need help with the following:

I have a form with fields named CartFee, CartNumber, LockerNumber, etc. If there is an entry in the CartFee field, I want the cursor to go to the CartNumber field and require the user to enter a CartNumber, but if the CartFee field is empty (ie null), I want the cursor to skip the CartNumber field and go to the LockerNumber field instead.
It also should NOT allow the user to enter a cartnumber if the CartFee is null.

I hope this is clear.

I would greatly appreciate any help you can offer me.

Thanks. CarolOB
 
Put the fields ijn the order you want them. Go to form properties and set the tab order and tab stop properties.

Then, in the field that requires an entry, enter the following in the on exit or on change event.

If me.txtCartFee = "" then
me.txtCartNumber.enabled = false
me.txtLockerNumber.setfocus
Else
'code here.
End if
Tyrone Lumley
augerinn@gte.net
 
Thank you for your response.

I implemented your code into the on exit event, but I received the following message:
Compile error!
method or data member not found

and the debugger showed the error at me.txtCartFee.
(I did notice when I was typing in the code, txt didn't seem to be an available choice)
After receiving the above mentioned error, I removed the txt references (ie me.CartFee instead of me.txtCartFee) and I didn't get the compile error, however, the cursor did not move to the LockerNumber field as I had hoped it would.

Do you have any other ideas that I could try?

Thank you CarolOB
 
Hi!

Instead of If Me.CartFee = "" try If Nz(Len(Me.CartFee),0) = 0. See how that works.

hth
Jeff Bridgham
 
Hi,

Thanks for your response.

I tried the NZ code you suggested, but I got another
Compile Error!
Syntax error

CarolOB
 
Another way to do this is to set the Enabled property of your CartNumber field to False, then enable it when Cartfee is not null. This makes the code a bit simpler in that you do not have to set the focus to the cartnumber field because if it becomes enabled, the cursor will move to it in tab order automatically.

Set the Tab Order and Tab Stop properties as Tyrone suggested and disable the CartNumber field. Then, in the After Update event of the CartFee field add this code (changing the field names to your correct field names)

Private Sub CartFee_AfterUpdate()
If Not IsNull(CartFee) Then
CartNumber.Enabled = True
End If

End Sub

In the Form's OnCurrent Event, add the following code

Private Sub YourFormName_OnCurrent()
Call CartFee_AfterUpdate
End Sub

You will need this code to run the procedure whenever you view the records, otherwise the CartNumber field will always be disabled.

HTH
Lightning
 
Hi,
Sorry for the delay in writing back. I've tried all the suggestions, but I still haven't succeeded in getting this to work.

It appears that I neglected to mention in my e-mail that the CartFee field gets its value from a combo box. Would that have any bearing on the problems I'm having?

Sorry if this should have been stated before now.

Thanks CarolOB
 
Hi,
I just went back and tried these suggestions again (in case I made a typo or something) and sure enough it's now working correctly with the code sent to me by Databaseguy.

Thank you to each of you for your responses and your support. I REALLY appreciate your help.

Thanks again CarolOB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top