goto problem

D

DW

Got a little problem with goto line
I have got a text box that is bound that I am trying to get to increase in
number by 1 for each record until it gets to 4 then close the form. I have
tried it several ways and I am still having problems. The textbox is locked
so no one can enter data into it. The form that it is on has 3 other bound
textboxes related to the same record. This code is in the first textbox to
receive focus when the form loads. It will change the value from 0 to 1, but
after that it wont. I unlocked the textbox for spite and put a 2 in and when
you click on the textbox that this code is in it will change the number. How
come it wont if you tab through the form. I t looks like it would when the
textbox receives focus.
Stumped!

Private Sub
Calibration_Begining_Meter_Readings_GotFocus()
If Text16.Value = 0 Then GoTo line1
If Text16.Value = 1 Then GoTo line2
If Text16.Value = 2 Then GoTo line3
If Text16.Value = 3 Then GoTo line4 Else GoTo line5
line1:
Text16.DefaultValue = ""
Text16.Value = 1
GoTo lastline
line2:
Text16.Value = 2
GoTo lastline
line3:
Text16.Value = 3
GoTo lastline
line4:
Text16.Value = 4
GoTo lastline
line5:
Beep
lastline:
Beep
End Sub

the close statement is on the last textbox to recieve focus. The code is in
the exit event
if text16.value = 4 then
DoCmd.Close.ACForm, (calibration)
 
L

losmac

Do You want to go for 4 records in form?

Declare new variable in top of your form code, below the
words:
Option Compare Databe
Opion Explicit

Dim i as Long

Insert new button on the form: Button1

In the procedure OnClick for Button1 paste code:
'i = 0 'first record - current record when You open form
i = i+1
Select case i
Case 1 To 3 ' go to next record
DoCmd.GoToRecord , , acNext
Case 4 'go out
DoCmd.Close acForm, Me.Name
End Select



losmac
 
D

Dirk Goldgar

DW said:
Got a little problem with goto line
I have got a text box that is bound that I am trying to get to
increase in number by 1 for each record until it gets to 4 then close
the form. I have tried it several ways and I am still having
problems. The textbox is locked so no one can enter data into it. The
form that it is on has 3 other bound textboxes related to the same
record. This code is in the first textbox to receive focus when the
form loads. It will change the value from 0 to 1, but after that it
wont. I unlocked the textbox for spite and put a 2 in and when you
click on the textbox that this code is in it will change the number.
How come it wont if you tab through the form. I t looks like it would
when the textbox receives focus.
Stumped!

Private Sub
Calibration_Begining_Meter_Readings_GotFocus()
If Text16.Value = 0 Then GoTo line1
If Text16.Value = 1 Then GoTo line2
If Text16.Value = 2 Then GoTo line3
If Text16.Value = 3 Then GoTo line4 Else GoTo line5
line1:
Text16.DefaultValue = ""
Text16.Value = 1
GoTo lastline
line2:
Text16.Value = 2
GoTo lastline
line3:
Text16.Value = 3
GoTo lastline
line4:
Text16.Value = 4
GoTo lastline
line5:
Beep
lastline:
Beep
End Sub

the close statement is on the last textbox to recieve focus. The code
is in the exit event
if text16.value = 4 then
DoCmd.Close.ACForm, (calibration)

Since this is a bound text box, it has a new value for each record. It
seems likely that the field to which it is bound has its Default Value
set to 0 in the table design, so for each new record the field has an
initial value of 0. I think that would explain the behavior you're
seeing.

I'm not at all sure what you're trying to do here, but I don't think
you're going about it the right way. Would you care to explain the
bigger picture of what you're trying to accomplish, and give some
details of your table and form design? That would help a lot in
advising you.
 
D

DW

The table file is linked to this database and has the following fields:
-calibration begining meter readings
-calibration ending meter reading
-cost per gallon
-pump number
-date entered

the textboxes in the form are bound to one of the above:

:textbox "year" has a control soucre of "date entered"
default value of =cdate(mmmm/yyyy)

:textbox "text16" has a control source of "pump number"
default value set to 1

:textbox "calibration begining meter readings" has the control of
"calibration begining meter readings"

:textbox "calibration ending meter reading" has the control of "calibration
ending meter reading"

:textbox "cost per gallon" hast the control of "cost per gallon"

what I am trying to do is to have this form popup with the correct
date(which it does)
pump number starting at 1
and the other 3 textboxes blank
the last textbox on the form is "cost per gallon", when you come out of
this, it starts a new record(good)
now the next record should have the date(which it does)
and the pump number should have changed to 2, then you enter your data and
the process go on with every record until you get to the forth one. When you
get done entering data on the forth record the form needs to close.
Calibration only happens once a month, so when the form is opened every
month ,it needs to start a new record. Now the date needs to change(which it
does) and the pump number needs to start at 1 and as every record is entered
up to the forth record, the pump number needs to change according until the
forth record.
Hope I explained this well enough, if not write back and I will try to
explain better
 
D

Dirk Goldgar

DW said:
The table file is linked to this database and has the following
fields:
-calibration begining meter readings
-calibration ending meter reading
-cost per gallon
-pump number
-date entered

the textboxes in the form are bound to one of the above:

default value of =cdate(mmmm/yyyy)

default value set to 1

"calibration begining meter readings"



what I am trying to do is to have this form popup with the correct
date(which it does)
pump number starting at 1
and the other 3 textboxes blank
the last textbox on the form is "cost per gallon", when you come out
of this, it starts a new record(good)
now the next record should have the date(which it does)
and the pump number should have changed to 2, then you enter your
data and the process go on with every record until you get to the
forth one. When you get done entering data on the forth record the
form needs to close. Calibration only happens once a month, so when
the form is opened every month ,it needs to start a new record. Now
the date needs to change(which it does) and the pump number needs to
start at 1 and as every record is entered up to the forth record,
the pump number needs to change according until the forth record.
Hope I explained this well enough, if not write back and I will try to
explain better

If I understand what you're asking, you have two specific questions:

1. How to make the pump number increase automatically, starting at 1 and
increasing by 1 for each new record.
2. How to make the form close when data has been entered for Pump 4.

Both of these questions could be handled by a little code in the form's
AfterUpdate event. First, in the form's Design View, set the Default
Value property for the Text16 text box (bound to [pump number]) to 1.
Then create an event procedure for the form's AfterUpdate event like
this:

'----- start of code -----
Private Sub Form_AfterUpdate()

If Me!Text16 = 4 Then
DoCmd.Close acForm, Me.Name, acSaveNo
Else
Me!Text16.DefaultValue = """" & (Me!Text16 + 1) & """"
End If

End Sub
'----- end of code -----

With this code in place, each time you save a record, the next record's
pump number will default to the next pump number in sequence, until
you've saved a record for pump number 4, at which point the form will
close.
 

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

Similar Threads

SetFocus problem 3
Combo Box 1
vba if and goto statements 4
Prevent Printing 1
Combo box 1
Selection Change - Data Sub Totals? 2
Prevent macro calculate if text in the range 5
Report Question 12

Top