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

Help with Data Entry = Yes problem . . .

Status
Not open for further replies.

OverDrive

IS-IT--Management
Dec 11, 2000
268
US
Does anyone know why this code gives me a debug error when I set my form's "Data Entry" to "Yes"

-------------------------------
Dim rst As Recordset

Set rst = Me.RecordsetClone

'Set a field with the total number of records
Me![Field1] = rst.RecordCount

If (Not Me.NewRecord) Then
rst.Bookmark = Me.Bookmark
'Set a field with the current record number
Me![Field2] = rst.AbsolutePosition + 1
Else
Me![Field2] = -1
End If
-----------------------------------

I am trying to have the form open with all blanks forcing the user to choose an employee from the combobox I have which will autopoulate the rest of the fields once chosen.

The code is a record counter that counts the records in the database and displays it on the Form (example: Record 4 of 6).

Everything works fine until I choose the "Data Entry" and set it to "Yes"

Does anyone know why this is giving me an error?

Please Help!!

Chance~
 
Hi!

I hope this will solve your problem:
Me![Field2] = Me.CurrentRecord

Aivars

LOL My summer holidays will start next week!
 
Thanks for the tip bud . . . I think my problems run deeper than I thought . . .

Have a good holiday!

Thank You!
Chance~
 
Hi again!

Here are solution of imitation of Navigation Buttons.
Maybe this is thing what do you try to solve?

I created one Textbox named txtCurrentRecord (enabled) and other one named txtTypeUnitCount (disabled) for imitation of Navigation Buttons. Both textboxes are placed cheek by jowl.
txtCurrentRecord is unbound, but txtTypeUnitCount Control Source is
=&quot;of &quot; & IIf([txtCurrentRecord]<=DCount(&quot;TypeUnitNo&quot;;&quot;XUNA&quot;);DCount(&quot;TypeUnitNo&quot;;&quot;XUNA&quot;);[txtCurrentRecord]) - it shown recordcount of form.
Form's recordsource is based on table &quot;XUNA&quot;

Textbox txtCurrentRecord is created for going to entered record (number) like record number of Navigation Buttons

Private Sub txtCurrentRecord_AfterUpdate()
On Error GoTo Err_txtCurrentRecord_AfterUpdate
Dim rst As Recordset
Dim lngRecordCount As Long
Dim lngCurrentRecord As Long

lngCurrentRecord = Me.CurrentRecord
Set rst = Me.RecordsetClone
lngRecordCount = rst.RecordCount

If Me.txtCurrentRecord <> Me.CurrentRecord Then
Select Case Me.txtCurrentRecord
Case Is <= 0
Me.txtCurrentRecord = 1
Case Is > lngRecordCount
If Me.NewRecord Then
Me.txtCurrentRecord = lngCurrentRecord
Else
Me.txtCurrentRecord = lngRecordCount
End If
End Select
If Me.txtCurrentRecord <> Me.CurrentRecord Then
DoCmd.GoToRecord , , acGoTo, Me.txtCurrentRecord
End If
End If
rst.Close
Set rst = Nothing

Exit_txtCurrentRecord_AfterUpdate:
Exit Sub

Err_txtCurrentRecord_AfterUpdate:
If Err.Number = 2105 Then
Resume Next
Else
MsgBox &quot;Error No &quot; & Err.Number & vbLf & Error$, , Me.Name & &quot; Sub txtCurrentRecord_AfterUpdate&quot;
Resume Exit_txtCurrentRecord_AfterUpdate
End If

End Sub


Aivars
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top