Basic Macro Help

ljm32

New member
Local time
Today, 10:30
Joined
Nov 3, 2011
Messages
2
Dear All,

Im new to Access and could really do with some help. I'm trying to make sure that we enter data correctly on a form I've created in Access. I'm trying (badly) to write a bit of conditional coding in vba to get the form to autofill other text boxes in the same form based on the contents of a text box. So if I type the number 1 in the 'text box number 1' then 'text box number 2' and 'text box number 3' fill automatically with 99. But if I type the number 0 in 'text box 1' then then 'text box number 2' and 'text box number 3' are made null and are ready to enter corresponding information. My problem is that if I mistankenly enter 1 and 99 comes up in the other boxes, then I return to text box 1 and correctly enter 0, the 99's stay where they are and I cant change them.

What would you advise? How can I get rid of the 99's when i correct text box 1and leave text box 2 and 3 empty and ready to have the correct text entered

Here's a sample of the terrible code Im using:

Private Sub text_box_1_LostFocus()

If (Me.text_box_1) = 0 Then

Me.text_box_2 = "99"
Me.text_box_3 = "99"

Else

If (Me.text_box_1) <> 0 Then

Me.text_box_2 = ""
Me.text_box_3 = ""
End If

End If

End Sub

Best wishes ljm32
 
I think the parentheses are throwing you off. See if this works:

Code:
If Me.text_box_1 = 0 Then
  Me.text_box_2 = "99"
  Me.text_box_3 = "99"
Else
  Me.text_box_2 = ""
  Me.text_box_3 = ""
End If
 
Beauty, seems to have worked.
 
Happy to help, and welcome to the site by the way!
 

Users who are viewing this thread

Back
Top Bottom