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

Navigation buttons that don't allow new records

Status
Not open for further replies.
May 5, 2000
168
US
Hello;
I want to use navigation buttons, but I don't want the new record button to be available because I have written my own procedure for adding new records, do I have to create my own custon buttons, and if so can someone direct me to some code to do this.
 
Here you go. I think it's self-explanatory. Just name a command button for each action (Go2First, Go2Next, Go2Last and Go2Prev). If you're at the last record and hit Go2Next it wraps around to the first record, so it won't go to a new record. Likewise, if you're on the first record and hit Go2Prev it wraps to the last record.

Code:
Private Sub Go2First_Click()
On Error GoTo Err_Go2First_Click
    DoCmd.GoToRecord , , acFirst
    Exit_Go2First_Click:
Exit Sub
Err_Go2First_Click:
    MsgBox Err.Description
    Resume Exit_Go2First_Click
End Sub

Private Sub Go2Next_Click()
On Error GoTo Err_Go2Next_Click
   DoCmd.GoToRecord , , acNext
Exit_Go2Next_Click:
    Exit Sub
Err_Go2Next_Click:
    DoCmd.GoToRecord , , acFirst
End Sub

Private Sub Go2Last_Click()
On Error GoTo Err_Go2Last_Click
    DoCmd.GoToRecord , , acLast
Exit_Go2Last_Click:
    Exit Sub
Err_Go2Last_Click:
    MsgBox Err.Description
    Resume Exit_Go2Last_Click
End Sub

Private Sub Go2Prev_Click()
On Error GoTo Err_Go2Prev_Click
    DoCmd.GoToRecord , , acPrevious
Exit_Go2Prev_Click:
    Exit Sub
Err_Go2Prev_Click:
    DoCmd.GoToRecord , , acLast
End Sub

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
This looks good, do you have a feature that will display the record count, like "1 of 4538 records"
 
If your form is based on a query:

Code:
Private Sub Form_Current()
	If Not Me.NewRecord Then
		Me.Caption = "Record  " & CurrentRecord & "  Of  " & RecordsetClone.RecordCount & "  Records"
	Else
		Me.Caption = "Record  " & CurrentRecord & "  Of  " & (RecordsetClone.RecordCount + 1) & "  Records"
	End If
End Sub

If your form is based on a table, instead of a query, you'll have to add this:

Code:
Private Sub Form_Load()
	DoCmd.GoToRecord , , acNext
	DoCmd.GoToRecord , , acFirst
	Me.Caption = "Record  " & CurrentRecord & "  Of  " & RecordsetClone.RecordCount & "  Records"
End Sub

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Sorry, forgot to add that the above code lists the record number (X record of X records) in the title bar of the form. To place this info in elsewhere, substitute your label name for Me.Caption.

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
>>>do I have to create my own custon buttons

No, you don't have to. You could set the "Allow Additions" property of your form to "No". This will disable the "New Record" button.
 
Thank you. I have chosen to go with the default access buttons. I have set the allowadditions property of the form to "no". Then I have created a "New Record" button. Using the "on click" property is say:
me.allowadditions = true

This works fine, but I get a message box saying "object required". Am I missing something?

Then I have a button to save the record and on click I set
me.allosadditions = false. I get the same "object required" message, and the allow addtions property does not set to false.

Any ideas here? Thank you
 

Not really sure, except that Me.AllowAdditions = True doesn't actually take you to a new record. Try:

Code:
Me.AllowAdditions = True
DoCmd.GoToRecord , , acNewRec

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Thanks.
It turned out that I had included code for an object that I had deleted.
 
Alternatively why don't you just set the property of the form to Allow Additions to No.

If you look at all the form properties there is a lot you can do with code.

Leon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top