473,378 Members | 1,333 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Navigation AddNew Record woes

Hello and TIA for your consideration.

I have created several db's for a non-profit and they want custom
navigation buttons to display "You are on the first record, last
record, etc". With this ng help I've created code for all except the
add new record command button.

If I create individual sub functions behind each form, no problem.

The problem is I am trying to create a re-usable module.

CBF (works):
Private Sub cmdNewRec_Click()
Dim rs As DAO.Recordset

Set rs = Me.RecordsetClone

If Me.NewRecord Then
MsgBox "You are on a blank record", vbOKOnly, "Data Navigation"
ElseIf Not rs.EOF Then
DoCmd.GoToRecord , , acNewRec
Me.txt_radioNbr.SetFocus
End If

Set rs = Nothing

End Sub

Function (add new record is stepped into but the cursor stays on
current record):
Function NavButtons(strNav As String)
'Purpose: Re-usable module for navigating the form
'Called by: Navigation buttons on forms
'Variables: First, Previous, Next, Last and New
'Returns: Nothing
'Created: Terry Wickenden
Dim frmCurrent As Form
Dim rsNavigate As DAO.Recordset

On Error GoTo ErrNavButtons

Set frmCurrent = Screen.ActiveForm
Set rsNavigate = frmCurrent.RecordsetClone

Select Case strNav
Case "First"
If frmCurrent.CurrentRecord = 1 Then
MsgBox "You are on the first record", vbOKOnly, "Data Navigation"
Else
rsNavigate.MoveFirst
End If
Case "Prev"
If frmCurrent.CurrentRecord = 1 Then
MsgBox "You are on the first record", vbOKOnly, "Data
Navigation"
Else
rsNavigate.MovePrevious
End If
Case "Next"
If frmCurrent.NewRecord Then
MsgBox "You are on a blank record", vbOKOnly, "Data
Navigation"

ElseIf frmCurrent.CurrentRecord =
frmCurrent.RecordsetClone.RecordCount Then
MsgBox "You are on the last record", vbOKOnly, "Data
Navigation"
Else
rsNavigate.MoveNext
End If
Case "Last"
If frmCurrent.CurrentRecord =
frmCurrent.RecordsetClone.RecordCount Then
MsgBox "You are on the last record", vbOKOnly, "Data
Navigation"
Else
rsNavigate.MoveLast
End If
Case "new"
If frmCurrent.NewRecord Then
MsgBox "You are on a blank record", vbOKOnly,
"Data Navigation"
Else
DoCmd.GoToRecord , , acNewRec
End If

End Select
frmCurrent.Bookmark = rsNavigate.Bookmark
Set rsNavigate = Nothing

ExitNavButtons:
Exit Function

ErrNavButtons:
MsgBox Error$
Resume ExitNavButtons

End Function

Again Thanks for any suggestions.
Jul 2 '08 #1
0 1927

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Robert Neville | last post by:
I am having some trouble with some old code revolving around custom form navigation buttons. My main form has a sub-form with these custom navigation buttons. In other words, the code should be...
2
by: Ellen Manning | last post by:
I'm developing an A2K adp that contains doctor info and the months they are not available for teaching. A doctor can be unavailable for some months for one year and other months for another year. ...
25
by: dixie | last post by:
I have some code that adds new records into a table for each ID in a list box when a button on a form is clicked. This works fine. My problem now is that I wish to be able to edit all the records...
2
by: Harold | last post by:
Sat I have a customers table with the fields CustomerID and Customer and I use the recordset.addnew method to add a new record to the table. What is the best way to get the CustomerID of the new...
2
by: pillmill | last post by:
I replaced AddNew statments with INSERT INTO, but am unable to write to the same tables. Foreign keys violations are the main errors. Why are these occuring ? Before: set rs3=...
8
by: MLH | last post by:
Here's a snippet from A97 HELP on AddNew... The record that was current before you used AddNew remains current. If you want to make the new record current, you can set the Bookmark property to...
0
by: polocar | last post by:
Hi, I have noticed a strange behaviour of CurrencyManager objects in C# (I use Visual Studio 2005 Professional Edition). Suppose that you have a SQL Server database with 2 tables called "Cities"...
14
by: Rational Repairs | last post by:
I am trying to create global code for navigation use in all my forms -- including subforms. I searched, and searched, but can not find how to globally reference a subform object. I need to have the...
1
by: teenagelcruise | last post by:
hi, i have a problem with my code which is i cannot update and addnew data into the database but i can delete the data.plz give me an idea.this is my code that i wrote. <html> <head> <meta...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.