PC Review


Reply
Thread Tools Rate Thread

Access Form Next Record button / move next

 
 
sjsean
Guest
Posts: n/a
 
      29th Apr 2009
I am trying to build a form in access which in the top portion would
contain master records and a subform would contain detail records.

My current issue lies in that I have a "Next Record" button on the
form to move from one master record to the next in the recordset which
is created as the form is opened.

When I click the next record button the first time it does move to the
next record, but then subsequent clicks do nothing. What am I doing
wrong. Also is there a better programming style/way to do one
recordset when the form opens and use that recordset across multiple
subroutines? I am going to want to do a routine for next record and
previous record as an example.

Private Sub Next_record_Click()
Dim address_issues As DAO.Database
Dim accts As DAO.Recordset
Dim rssql As String
Set address_issues = CurrentDb

rssql = "select instill_code, organization_name, acct_num, ACCT_NAME,
BUYER_ADDRESS1, BUYER_ADDRESS2, BUYER_CITY, BUYER_STATE,
BUYER_POSTAL_CODE, DPSU_SAP, DPSU_ORG_NAME, UPDATED_BY FROM
TBL_DPSU_TO_MAP WHERE DPSU_SAP = '';"

Set accts = address_issues.OpenRecordset(rssql, dbOpenDynaset)

With accts

Do Until accts.EOF



Me![Seller Name] = accts.Fields("instill_code").Value
Me![Acct Num] = accts.Fields("acct_num").Value
Me![Acct Name] = accts.Fields("acct_name").Value
Me![Address1] = accts.Fields("BUYER_ADDRESS1").Value
Me![Address2] = accts.Fields("BUYER_ADDRESS2").Value
Me![City] = accts.Fields("BUYER_CITY").Value
Me![State] = accts.Fields("BUYER_STATE").Value
Me![Postal Code] = accts.Fields("BUYER_POSTAL_CODE").Value
Me![DPSU_SAP] = accts.Fields("dpsu_sap").Value
Me![DPSU_ORG_NAME] = accts.Fields("dpsu_org_name").Value
Me![UPDATED_BY] = accts.Fields("updated_by").Value
..MoveNext

Loop
End With

accts.Close
address_issues.Close

End Sub
 
Reply With Quote
 
 
 
 
Albert D. Kallal
Guest
Posts: n/a
 
      29th Apr 2009

You "next record" code re-assigns and re-loads the reocrdset which means it
going to start at the 1st record every time, and then only move to the next
2nd record after that. So, each time you are re-loading the reocrdset...it
starts at the beginnning..

However, why all such code? Just use a bound form.

I you must assign the sql, then go:

rssql = "select instill_code, organization_name, acct_num, ACCT_NAME,
BUYER_ADDRESS1, BUYER_ADDRESS2, BUYER_CITY, BUYER_STATE,
BUYER_POSTAL_CODE, DPSU_SAP, DPSU_ORG_NAME, UPDATED_BY FROM
TBL_DPSU_TO_MAP WHERE DPSU_SAP = '';"

me.RecordSource = rssql

Then, use the built in navigation buttons, or place the following code
behind a button:

On Error Resume Next
DoCmd.GoToRecord acActiveDataObject, , acNext

In fact, why is this sql/recordset even being created here. Why not use a
bound form? If your form is bound, then we don't need that sql to be
assigned to the forms reocrdset, but just the navigation code as above.


--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
(E-Mail Removed)


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use Form button to move current record to another table JMageeirbc@gmail.com Microsoft Access 4 14th Dec 2007 04:15 PM
Access:How can a form button moves the record to another table? =?Utf-8?B?dm5vcm10aA==?= Microsoft Access Form Coding 6 6th Oct 2007 01:44 AM
'new record' button not active in Access 2007 form (old 2003 form) =?Utf-8?B?Q2hyaXMgU21pdGg=?= Microsoft Access Forms 2 26th Jun 2007 04:03 AM
MS Access - Move to a Specific Record in a Form. nichole Microsoft Access Getting Started 1 27th Jul 2006 01:54 PM
Access 97 Click button in form and view the report of a selected record in sub-form Céline Brien Microsoft Access Form Coding 5 27th May 2004 09:50 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:33 PM.