how to check previous record

D

Dirk Goldgar

gator said:
how do I check if the current record is the first record?


Do you mean, whether it's the first record on the form, so that you can't
move to a previous record? The form's CurrentRecord property will be 1.
 
G

gator

does this seem feasible to grab a previous record value?
Private Sub Form_Current()
If Me.CurrentRecord = 1 Then
Cancel = True
Else
DoCmd.GoToRecord acActiveDataObject, , acPrevious
newValue = Me.TranType.Value
DoCmd.GoToRecord acActiveDataObject, , acNext
Me.TranType.Value = newValue
End If
End Sub
 
D

Dirk Goldgar

gator said:
does this seem feasible to grab a previous record value?
Private Sub Form_Current()
If Me.CurrentRecord = 1 Then
Cancel = True
Else
DoCmd.GoToRecord acActiveDataObject, , acPrevious
newValue = Me.TranType.Value
DoCmd.GoToRecord acActiveDataObject, , acNext
Me.TranType.Value = newValue
End If
End Sub


No, there is a much easier way to do it, and one that doesn't involve
changing records on the form, with the danger that gives of either forcing a
record-save when you don't want one or maybe having an error because the
current record can't be saved.

Try this instead; it's untested, but it should be close:

'----- start of (untested) code -----
Private Sub Form_Current()

If Me.CurrentRecord > 1 Then
With Me.RecordsetClone
.Bookmark = Me.Bookmark
.MovePrevious
Me.TranType.DefaultValue = Chr(34) & !TranType & Chr(34)
End With
End If

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

I've taken the liberty of changing the effect from actually modifying the
value of TranType each time you go to a new record, to just setting its
default value. That keeps you from dirtying every record just by visiting
it, but fills in the TranType for new records when you make some other
entry. I thought that would be more likely what you wanted, but I could be
wrong. If so, just explain what you're trying to do and why, and I'll give
you some revised code.
 
G

gator

what do you think about this one....it's the option value I'm after....
Private Sub Frame0_AfterUpdate()
If Frame0.Value = 1 Then
Frame0.DefaultValue = 1
Else
Frame0.DefaultValue = 2
End If
End Sub
 
D

Dirk Goldgar

gator said:
what do you think about this one....it's the option value I'm after....
Private Sub Frame0_AfterUpdate()
If Frame0.Value = 1 Then
Frame0.DefaultValue = 1
Else
Frame0.DefaultValue = 2
End If
End Sub


Doing it that way is even better, so long as you don't need the default
value to be already set for the first record on the form.
 

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