Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Moving Control To Previous Record Field


I hope this is the right forum for this...

I have an Access 2000 sub-form with a bit of VB programming behind it. The fields are layed out like this -

Field1 Field2 Field3

Fields 2 and 3 have some error checking that works fine. Problem I have is that when Field3 finishes it's error checking it creates a new record and goes to Field1 of the new record, leaving a null value in Field3 of the previous record.

Can I somehow do the error checking in Field3 and then have the focus stay there?

Thanks all!
John




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Moving To Next,previous,first,last Record Problem
Thank you
its me again, sad to say but im encountering a new problem in viewing my file
in this problem im encountering problem
when i press the next and previous button it does'nt show the message box warning and on when i click
the next button it only move once and when i click previous it displays an error that
operation is not allowed in this context and when i click the last button
it will say that rowset doest not support fetching backward
i look at ADOTUT file and the code i use is almost the same except i use textbox instead of listbox
i also try the DO UNTIL syntax but still i encounter errors
What could be the problem?
Please Help Me



Code:
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset

Private Sub Command1_Click()

Set conn = New ADODB.Connection
conn.Provider = "Microsoft.Jet.OLEDB.4.0;"
conn.Open (App.Path & "cmsdb.mdb")

Set rs = conn.Execute("SELECT lastname FROM cmstable")


If rs.EOF = True Then MsgBox "no more records"

rs.MoveNext
lname.Text = rs("lastname")

conn.Close

End Sub

Private Sub Command2_Click()
Set conn = New ADODB.Connection
conn.Provider = "Microsoft.Jet.OLEDB.4.0;"
conn.Open (App.Path & "cmsdb.mdb")
Set rs = conn.Execute("SELECT lastname FROM cmstable")

If rs.BOF = True Then MsgBox "no more records"
rs.MovePrevious
lname.Text = rs("lastname")

conn.Close


End Sub

Private Sub Command3_Click()
Form3.Show
Unload Me
End Sub

Private Sub Command4_Click()
Set conn = New ADODB.Connection
conn.Provider = "Microsoft.Jet.OLEDB.4.0;"
conn.Open (App.Path & "cmsdb.mdb")
Set rs = conn.Execute("SELECT lastname FROM cmstable")


rs.MoveFirst
lname.Text = rs("lastname")

conn.Close
End Sub

Private Sub Command5_Click()
Set conn = New ADODB.Connection
conn.Provider = "Microsoft.Jet.OLEDB.4.0;"
conn.Open (App.Path & "cmsdb.mdb")
Set rs = conn.Execute("SELECT lastname FROM cmstable")


rs.MoveLast
lname.Text = rs("lastname")

conn.Close
End Sub

Set Field Value From Previous Record In A New Record
Hi All

I am trying to get value of a field in the last record to another field in the new recordset in VB.

Access Table, VB6

Form has 4 fields. 1.PreviousBalance 2. PaymentDate 3.AmountPaid 4. NewBalance.

I want to set the NewBalance from the Last record as PreviousBalance in the New record as I click AddNew.

I sincerely hope someone could help me.

My email: alfalfa@spiceisle.com

Thanks

Following is my failed code.

Option Explicit
Dim MyPath, Last


Private Sub Command1_Click()
'Data1.DatabaseName = MyPath & "HouseLoan.mdb"
'Data1.RecordSource = "select * from Balance"
' Data1.Refresh
' Data1.Recordset.MoveLast
'If Data1.Recordset.Fields("NewBalance") = Format(0, "Currency") Then
'txtFields(3).Text = Format(0, "Currency")
'txtFields(3).ForeColor = &HC00000

'Else
' txtFields(3).SetFocus
'txtFields(3).Text = Format(Data1.Recordset.Fields("NewBalance"), "Currency")
'txtFields(3).ForeColor = &HFF&
'End If
datPrimaryRS.Recordset.AddNew
Data1.DatabaseName = MyPath & "HouseLoan.mdb"
Data1.RecordSource = "select * from Balance"
Data1.Refresh
Data1.Recordset.MoveLast
If Data1.Recordset.Fields("NewBalance") = Format(0, "Currency") Then
txtFields(3).Text = Format(0, "Currency")
txtFields(3).ForeColor = &HC00000

Else
txtFields(3).SetFocus
txtFields(3).Text = Format(Data1.Recordset.Fields("NewBalance"), "Currency")
txtFields(3).ForeColor = &HFF&
End If
'txtFields(3).Text = txtFields(1).Text
txtFields(1).Text = ""
txtFields(0).Text = ""
txtFields(2).Text = ""


End Sub

Private Sub DTPicker1_Change()
txtFields(2).Text = DTPicker1.Value
End Sub
Private Sub Form_Load()
MyPath = App.Path
If Right(MyPath, 1) <> "" Then
MyPath = MyPath & ""
End If
On Error Resume Next
datPrimaryRS.RecordSource = MyPath & "HouseLoan.mdb"
'Data1.DatabaseName = MyPath & "HouseLoan.mdb"
'datPrimaryRS.Recordset.RecordCount 1
'Data1.Recordset.MoveLast
'Text1.Text = txtFields(1).Text
End Sub
Private Sub Form_Unload(Cancel As Integer)
Screen.MousePointer = vbDefault
End Sub

Private Sub datPrimaryRS_Error(ByVal ErrorNumber As Long, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, fCancelDisplay As Boolean)
'This is where you would put error handling code
'If you want to ignore errors, comment out the next line
'If you want to trap them, add code here to handle them
MsgBox "Data error event hit err:" & Description
End Sub

Private Sub datPrimaryRS_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
'This will display the current record position for this recordset
datPrimaryRS.Caption = "Record: " & CStr(datPrimaryRS.Recordset.AbsolutePosition)
End Sub

Private Sub datPrimaryRS_WillChangeRecord(ByVal adReason As ADODB.EventReasonEnum, ByVal cRecords As Long, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
'This is where you put validation code
'This event gets called when the following actions occur
Dim bCancel As Boolean

Select Case adReason
Case adRsnAddNew
Case adRsnClose
Case adRsnDelete
Case adRsnFirstChange
Case adRsnMove
Case adRsnRequery
Case adRsnResynch
Case adRsnUndoAddNew
Case adRsnUndoDelete
Case adRsnUndoUpdate
Case adRsnUpdate
End Select

If bCancel Then adStatus = adStatusCancel
End Sub

Private Sub cmdAdd_Click()
'On Error GoTo AddErr
datPrimaryRS.Recordset.AddNew
Me.txtFields(3) = Me.Text1
Exit Sub


AddErr:
MsgBox Err.Description
End Sub

Private Sub cmdDelete_Click()
On Error GoTo DeleteErr
With datPrimaryRS.Recordset
.Delete
.MoveNext
If .EOF Then .MoveLast
End With
Exit Sub
DeleteErr:
MsgBox Err.Description
End Sub

Private Sub cmdUpdate_Click()
On Error GoTo UpdateErr

datPrimaryRS.Recordset.UpdateBatch
Exit Sub
UpdateErr:
MsgBox Err.Description
End Sub

Private Sub cmdClose_Click()
Unload Me
End Sub

Private Sub txtFields_BeforeUpdate(Cancel As Integer)
Me.txtFields(3) = Me.Text1

End Sub

Private Sub txtFields_GotFocus(Index As Integer)
On Error Resume Next
' txtFields(2) = Format(datPrimaryRS.Recordset.Fields("PreviousBalance") + datPrimaryRS.Recordset.Fields("VisitFee") + datPrimaryRS.Recordset.Fields("ProcedureFee"), "Currency")
txtFields(1).Text = Format((txtFields(3) - txtFields(0)), "Currency")

Text1.Text = txtFields(1).Text
End Sub

'Data1.DatabaseName = MyPath & "HouseLoan.mdb"
'Data1.RecordSource = "select * from Balance"
'Data1.Refresh
' Data1.Recordset.MoveLast

' Me.txtFields(3).Text = Format(Data1.Recordset.Fields("NewBalance"), "Currency")
'txtFields(1).Text = ""
'txtFields(0).Text = ""
' txtFields(2).Text = ""

Not Moving With First, Next, Previous &amp; Last Buttons
Friends,

It shows like the following. But not moving with the firs, next, previous & last buttons.

1 of 5

If I have moved to second record using NEXT button also it shows just the same : 1 of 5.

The following is the code:

rs.Open "Select * from TOTALSTBL1 Order By SL", db, adOpenDynamic, adLockOptimistic
If Not rs.EOF Then
rs.MoveFirst
Text104.Text = "Record " & rs.AbsolutePosition & " of " & rs.RecordCount
End If

Moving To Previous/next Files
Hi

Does anybody know how to move forward and backward between text files. For example, I have a text in the textbox and I want to click on NEXT button and load new text file, or click on PREVIOUS button and go back to the previous file.

Thanks
Gosia

Date Field Stay The Same For Each Record When Using Calendar Control
I am new to this forum, but am in need of help with calendar control. I am using calendar control 10 to set a text field to whatever date is clicked on using the calendar control activex component. The problem occurs when I click to the next record - the date remains the same for every record thereafter. My question is this - how do I keep a date that is entered in one record from becoming the date for every other record, as well as keep that date that was entered in the previous record from changing to the date in the current record?

regards,
jba4718

Next Record And Previous
When I click on combo2...it displays all records in the required fields...I want to move to the next record that macthes the individual field name which is devname...and vice versa with the previous command.

Private Sub Combo2_Click()
Dim myclass As New clsDB
Dim sSQL As String

sSQL = "select * from projectinfo"


myclass.GetMyData sSQL

myclass.rsMyData.MoveFirst
Do While Not myclass.rsMyData.EOF
If myclass.rsMyData!devname = Combo2.Text Then
TxtDeveloperID.Text = myclass.rsMyData!developerID
Combo7.Text = myclass.rsMyData!devname
' TxtName.Text = myclass.rsMyData!devname
TxtPhone.Text = myclass.rsMyData!phone
Combo6.Text = myclass.rsMyData!requesttitle

Add New Record From Previous
Hi,

what I need to do is be able to add a new record to the mdb depending on what is in the previous record.

so for eg:

first record:                          balance=$0
previous record:        add $40        balance=$40
new record:             add $10        balance=$50

this is the code I have attached to an OK button:

    rsRecordSet.Source = "Select * From log_deposit"
    rsRecordSet.ActiveConnection = connConnection
    rsRecordSet.Open
    rsRecordSet.AddNew
    rsRecordSet("Period").Value = txtperiod.Text
    rsRecordSet("Date").Value = txtdate.Text
    rsRecordSet("Balance").Value = rsRecordSet("Balance") + txtamount.Text
    rsRecordSet.Update

So if anyone knows how to do this, pls reply

Thanks.

The Previous And Net Record (access).
I want to ad a controler to access form that shows some of the previous and the next record info (e.g. the name of the next employee etc.)
can it be done?

Move Previous And Record????
I have an access database, which I connect to using ado code.

I have text boxes which displays info from the fields in the database.

I have created a "Next", and "Previous" button, which the user can move between the database info.

BUT my Previous button is not working.

Here is the code for it


VB Code:
Private Sub Command3_Click()  If Record.BOF = True ThenMsgBox "This is the First record found!", vbInformationExit Sub Else Record.MovePrevious  ' I GET AN ERROR IF I AM ON THE FIRST RECORD, I THOUGHT I PREVENTED THIS ABOVE' if i am not on the first record, I get an error "The operation is not allows in this context" WebBrowser1.Navigate (Record.Fields("IMAGEPATH"))txtDateOfScan.Text = (Record.Fields("DATEOFSCAN"))txtTimeOfScan.Text = (Record.Fields("TIMEOFSCAN"))txtProduct.Text = (Record.Fields("PRODUCTNAME"))txtWeight.Text = (Record.Fields("WEIGHTOFPRODUCT"))txtPrice.Text = (Record.Fields("PRICEOFPRODUCT"))txtBarcode.Text = (Record.Fields("BARCODE"))txtUsername.Text = (Record.Fields("PERSONWHOSCANNED"))   End IfEnd Sub


I get an "either BOF or EOF is true" etc etc error.

ALSO, when I msgbox record.recordcount , I get -1 in the mesagebox. Even though there are records present. (I can go through them with the next button)


Hope someone can help me with this

Select The Previous Record ??
Hi,

Let say I have a table with these records..... ( 2,5,8,12,43,87,92 )

I run a query that is selecting record 12 and 43.

I need to know what was the record just before 12 .. which is 8.

Is there a simple way to do that, a query to select the record just before a specific line ?






Edited by - dbelley_office on 10/26/2004 8:03:32 AM

Why Do My Record Goes Back To Previous One....
Hi... I have a lillte problem here. I'm new to vb and databse. Anyway my problem is that whenever I get my qns 3 correct, the record doesn't move to qns 4. Instead it goes back to qns 2. Anyone can help? Thanks in advance..... This is what I code:

Option Explicit
Dim dbMIS As Database
Dim rst As Recordset
Dim MyVariable As String

Private Sub Form_Load()

Dim TotalRecordCount As Long

    Set dbMIS = DBEngine.Workspaces(0).OpenDatabase("D:watides3.mdb")
    Set rst = dbMIS.OpenRecordset("tblQuestionAnswer", dbOpenDynaset)
    
    rst.MoveFirst
    rst.MoveNext
    
            TotalRecordCount = rst.RecordCount
            If TotalRecordCount > 0 Then
                rst.MoveFirst
                Do While Not rst.EOF
                    lblQuestion.Caption = rst![Questions]
                    lblQuestionID.Caption = rst![QuestionID]
                    lblA.Caption = rst![A]
                    lblB.Caption = rst!
                    lblC.Caption = rst![C]
                    lblD.Caption = rst![D]
                    MyVariable = rst![Answer]
                    
                    'change the Lower Case input in the textbox to Upper Case
                    If txtAns.Text = LCase(txtAns.Text$) Then
                       txtAns.Text = UCase(txtAns.Text$)
                    End If
                    
                    Exit Do
                
                    While rst.EOF
                            MsgBox "Congrats!You have won the game. Thank you for playing", vbOKOnly
                    Wend
                Loop
            End If
    
    rst.Close
    dbMIS.Close
    
    
End Sub

Private Sub cmdHitMe_Click()
    
Set dbMIS = DBEngine.Workspaces(0).OpenDatabase("D:watides3.mdb")
Set rst = dbMIS.OpenRecordset("tblQuestionAnswer", dbOpenDynaset)

    If MyVariable = UCase(txtAns.Text$) Then
        MsgBox "Congrats!", vbOKOnly
        rst.MoveNext
            Do While MyVariable = UCase(txtAns.Text$)
                     lblQuestion.Caption = rst![Questions]
                     lblQuestionID.Caption = rst![QuestionID]
                     lblA.Caption = rst![A]
                     lblB.Caption = rst![B]
                     lblC.Caption = rst![C]
                     lblD.Caption = rst![D]
                     MyVariable = rst![Answer]
                     rst.MoveNext
            Loop
        txtAns.Text = ""
        txtAns.SetFocus
    Else
        MsgBox "Sorry wrong answer. You lose. Thank you for using this program.", vbOKOnly
        End
    End If
    
    rst.Close
    dbMIS.Close
    
End Sub

Display Previous Or Next Record
If I have something like this below,
it searches to show a few records if found of the same name,
how can i add 2 buttons to cmdPrev and cmdNext to display the previous record or the next record

thanks,


Code:

Private Sub cmdSearch_Click()
Dim strFindName
strFindName = InputBox("Search by Name")

Dim strsql As String
Dim rsCust As ADODB.Recordset
Set rsCust = New ADODB.Recordset

strsql = "SELECT * FROM Customer WHERE name LIKE '%" & strFindName & "%' order by id ASC"
Debug.Print strsql
rsCust.Open strsql, adconn, adOpenForwardOnly, adLockReadOnly

If rsCust.RecordCount > 0 Then
Label16.Caption = rsCust.RecordCount & " records found."
End If

If rsCust.EOF = False Then
Text1.Text = rsCust("id")
Text2.Text = rsCust("name")
Text3.Text = rsCust("address")
Text4.Text = rsCust("phone")
Text5.Text = rsCust("fax")
Text6.Text = rsCust("email")
Text7.Text = rsCust("website")
End If

rsCust.Close
Set rsCust = Nothing

Query Against Previous Record In Table?
Hi

I am trying to write a SQL statement for a colleague to run against an Oracle 9i database, but can't work out how to do it.

He has a table that contains (amongst other fields) a date, a starting monetary value and an ending monetary value.

What he wants to do is to determine if the ending value for a particular date is the same as the starting value for the next record that was written to the table. A record is written to the table most days. This problem is compounded by the fact that the dates aren't consecutive due to weekends, holidays, etc.

Neither of us can see a solution, so I wonder if anyone can help?

Thanks

[VB6 / ADO] Move To Next / Previous Record In A Second Form
Hi,

i have the following problem:

I have a datagrid that's filled with a recordset.
When the users doubleclicks a record, a new detailform is shown with all
info about the record.
Now i want to put 'next/previous' buttons on that detailform so that
the user can skip to the next/previous records from the datagrid in
the underlying window.
The current detailwindow should be updated with the values from the new active record.

Does anyone have a clue how to achieve this?

So far, i managed to do this (code on popup).

Code:
Private Sub cmdNext_Click() ' user clicked "next record"

    Dim v As Variant

    With mainform.DataGrid1
        v = mainform.DataGrid1.GetBookmark(1)
        ' Remove previously saved bookmark from collection
        If .SelBookmarks.Count <> 0 Then
           .SelBookmarks.Remove 0
        End If
        ' Append your bookmark to the collection of selected rows
        If Not IsNull(v) Then
           .SelBookmarks.Add v
        End If
     End With

End Sub


This is what happend when i click the button:
I see the bookmark changing to the next record, but the recordselector
doesn't follow, so this code works only once.

How do i move the selected record in the parent window?

grtz,
Jan

Sequential File: View Previous Record
I'm creating a wedding planner program using Sequential File.
From the picture I attacted, you can see that I have the previous button and next button ( to view previous and next record) . The problem is I don't know what command to type for the Previous button. I only know the command for the Next Button.

These are the code for the two button.

Private Sub cmdNext_Click()
Dim Name As String, Email As String, Phone As Integer, Mobile As Integer, Address As String, City As String, State As String, PostalCode As Integer, Country As String
If Not EOF(1) Then
Input #1, Name, Email, Phone, Mobile, Address, City, State, PostalCode, Country 'Read the file and store the record into variables
txtName.Text = Name
txtEmail.Text = Email
txtPhone.Text = Phone
txtMobile.Text = Mobile
txtAddress.Text = Address
txtCity.Text = City
txtState.Text = State
txtPostalCode.Text = PostalCode
txtCountry.Text = Country
Else

cmdNext.Enabled = False
Close #1
End If

End Sub

Private Sub cmdPrv_Click()
Dim Name As String, Email As String, Phone As Integer, Mobile As Integer, Address As String, City As String, State As String, PostalCode As Integer, Country As String
If Not BOF(1) Then
Input #1, Name, Email, Phone, Mobile, Address, City, State, PostalCode, Country 'Read the file and store the record into variables
txtName.Text = Name
txtEmail.Text = Email
txtPhone.Text = Phone
txtMobile.Text = Mobile
txtAddress.Text = Address
txtCity.Text = City
txtState.Text = State
txtPostalCode.Text = PostalCode
txtCountry.Text = Country
Else

cmdPrv.Enabled = False
Close #1
End If
End Sub

The cmdPrv_Click is not working. Can anyone help me ?

Passing Info From One Field In Many Records To One Field In One Record
Neophyte question: MS Assess 2003 - I have a contract form that has a subform attached for Series(s) sold. "Series(s) Sold" ranges from one to many and is a pulldown menu on the main form. I have a button that opens a pop up in order to input as many Series(s) as needed. My question is this: If I have more than one Series sold, can I transfer that data to a field on the main form, separate it by commas, and have the system not put a comma after the last series? I have worked with expressions, but can't seem to figure this one out.

So, the "Series(s) Sold" table is a result of linking the Contract table with the Series List, and one contract can have many records. I'm looking to return the value held in the "Series_1" field of many records to one field called "Series(s)" on my main form, and separate each record with a comma.

Any help would be appreciated,
L

Fixed Previous Problem By Refreshing. Now Field Edit Boxes Dont Show Current Data
I now refresh the recordset and this works.

but now the edit boxes I have linked to the fields become disasociated with the recordset.

ie I move to the first record but the edit boxes still show the record I added.

it only does this if I requery the recordset.

dataenvironment.rsTable.Requery

Thanx in advance
Jason

Centurion Software Australia

Search For A Record With Field 1 = This And Field 2 = That
Is is possible to search for a record where in the employeeid column there is the number 12345 and in the date requested column there is 3/5/2004?

Once this was executed if it existed it would do a message box "already exists". If not it would run code to add the record to the database.

Moving To Record
I have a control on my form that copies the contents of a form and a subform to a new record. Here is my code. On my form, how do I find the new record? That is to say, once I copy the record, the "old record" is still the one on my form. I want to move to the "new record" as part of the copy function.


'copy record to new Quote record
intQuoteID = Forms![Bid - Master Form]![Bid - Quote]![Quote ID]
Set dbs = CurrentDb
Set rstQuote = dbs.OpenRecordset("Bid - Quote")
rstQuote.AddNew
intNewQuoteID = rstQuote![Quote ID]
Debug.Print "New Quote ID " & intNewQuoteID
Debug.Print "New Quote ID " & rstQuote![Quote ID]
Debug.Print "Old Quote ID " & intQuoteID
rstQuote![Master Bid ID] = Forms![Bid - Master Form]![Master Project ID]
rstQuote![Other Mfr] = Forms![Bid - Master Form]![Bid - Quote]![Other Mfr]
rstQuote![Comments] = Forms![Bid - Master Form]![Bid - Quote]![Comments]
rstQuote.Update
Forms![Bid - Master Form]![Bid - Quote].Requery

'copy quote items to new quote items records
strSQL = "Select * " & _
"FROM [Bid - Quote Items] " & _
"WHERE [Quote ID] = " & intQuoteID
Set rstOldQuoteItem = dbs.OpenRecordset(strSQL)
Set rstNewQuoteItem = dbs.OpenRecordset("Bid - Quote Items")
Do While Not rstOldQuoteItem.EOF
rstNewQuoteItem.AddNew
rstNewQuoteItem![Quote ID] = intNewQuoteID
Debug.Print "New Quote ID " & rstNewQuoteItem![Quote ID]
rstNewQuoteItem![Quantity] = rstOldQuoteItem![Quantity]
Debug.Print "Qty " & rstOldQuoteItem![Quantity]
rstNewQuoteItem![Description] = rstOldQuoteItem![Description]
Debug.Print "Description " & rstNewQuoteItem![Description]
rstNewQuoteItem![Finish] = rstOldQuoteItem![Finish]
rstNewQuoteItem![Price] = rstOldQuoteItem![Price]
rstNewQuoteItem![Comments] = rstOldQuoteItem![Comments]
Debug.Print "Comment " & rstNewQuoteItem![Comments]
rstNewQuoteItem.Update
rstOldQuoteItem.MoveNext
Loop
Forms![Bid - Master Form]![Bid - Quote]![Bid - Quote Items]


Thanks is advance
Scott

Moving A Record
Hello Guys,

Im using a control called Adodc i was woundering if anyone can tell me how to move a record from tblName to tblSecondName with a click of a command button.

I use the followind code to save a record.?


vb Code Code:
If MsgBox("Are you sure you want to save the record?", vbQuestion + vbYesNo, "Saving...") = vbYes Then
Adodc2.Recordset.Fields("Subject") = cbosub.Text
Adodc2.Recordset.Update
distext
End If

Moving To A Record
I have a many side of a relationship in a table.
So ive created a form etc etc. Say Im looking at record #1
for simplicity lets say its an orders form with an order-details within it. Im looking at record 1 and it shows that it has 40 order details. I have a next / previous button and a first last button. What if I wanted to go to order detail #30 Id have to either keep pressing up or press first once and move down to 30. I dont want this. I want a text box that a user can enter the record they want to look at and it moves directly to it on hitting the enter key.

How do I do this via ADO?

Jon

Moving To The Next Record Ms Sql & Vb
Hi, im kinda new to working with vb and sql server, i need to be able to scroll through records but i have no idea how. As of right now my code is:
CODEDim cn As ADODB.Connection
Dim RS As ADODB.Recordset
Dim strSQL As String

Set cn = New ADODB.Connection
Set RS = New ADODB.Recordset

cn.Open "Driver={SQL Server};Server=server;Database=mydata;uid=;password='';"
strSQL = "select * from mytable"

RS.Open strSQL, cn, adOpenStatic, adLockReadOnly

Not Moving To Next Record
hi

all my staff will view for datas in this form. i am using scene table and panel table.

once they select scen1cbo(sceneid), other data will populate but now only one data is populated when i click 1 sceneid. It has more records linked to that sceneid.

(sceneid)SE01 A (panel field)
              B
                       C
                       D
when i select SE01 it displays 'A' alone i can't able to move to the next records B, C, D.

how to do that?

Code:Private Sub scenecombo_Click()

myquery = scenecombo.Text

Call rLOAD

 Do While storyboard!scenes <> myquery
 storyboard.MoveNext
 If storyboard!scenes = myquery Then
 panel_txt.Text = storyboard!Panel
 sequcombo.Text = storyboard!sequence
 action_txt.Text = storyboard!Action
 dialogue_txt.Text = storyboard!dialogue
  Image1.Picture = LoadPicture(App.Path & "images" & storyboard("filename"))
  End If
 Loop
 
accdb = "SELECT * FROM scene WHERE sceneid = '" & myquery & "' "
'Load SQL query into a variable

Set storyboard = CON.Execute(accdb, adOpenStatic)

End Sub

Moving To The Next Record Using VBA
Hi All - This is really bugging me. I'm trying to move to the next record located in a database. I can not use ADO I must use DAO. I've done this a million times in VB6 but something must be different in VBA(PS I'm doing eveyrthing in Access) because I can not get it to move to the next record. Any help would be greatly appreciated.

Moving To A Record
In an adodc recordset i want to move to a certain record and then return to the original record.
The code should look something like that:
sub cmd MoveTwice()
dim intOriginalRec as integer
intOriginalRec = adodc1.recordset.bookmark
adodc1.recordset.movelast
rem now i want to go back to the originalecord
addc1.recordset.GOTO(INTORIGINALREC)
End Sub


GOTO(INTORIGINALREC) is a method i invented of course. I'll be very gratefull to anyone who could teach me what method or what should i write instead! Thanks in advence !

Moving Data From One Field To Another
I have three fields of which fldA is populated, some parts of fldB are also and fldC is to where the data in fldB will be moved. Here is what I have so far:

Code:
Private Sub SwitchData(r As ADODB.Recordset)
Dim a, b As String
sSql = "SELECT fldA, fldB, fldC FROM Table1"
rs.Open sSql, cn
a = r.Fields("fldA").Value
b = r.Fields("fldB").Value

Do Until r.EOF
If b <> "" Then
'here is where I want to move the data from fldA to fldC
'And then move the data from fldB to fldA
'Only I am somewhat clueless on the how to
End If
Loop
End Sub
Any help would be greatly appreciated.

Kimt

How To Make A Form Default All Field Values To The Previous Records Values ?
Using Access2000 on 2k.

Have a database form in single form view (has a sub form in it).
Got a request to put in a button that will do the same as new record but default the new record to all the same values as the current forms record shows. I think there are several ways to do this, I'm afraid I'll pick the most difficult one if left to my own devices. (i.e. DAO recordset looping etc.)

The first thing I tried was using a wizard to add a button and chose the duplicate record offer from the wizard. It almost works but it presents a record without the arrow or the pencil in it, gives it a record number that makes me think it has appended it. but when I move away from the record and back to it again, it's empty.

If I right click and copy and then paste it does what I expect it to. That is put the copied information in the end record.
But the user doesn't want to copy and paste, they just want to push the button and then modify the needed fields.

I wizard gave me code that looks like this:
Private Sub cmdDupRec_Click()
On Error GoTo Err_cmdDuplicate_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append

Exit_cmdDuplicate_Click:
Exit Sub

Err_cmdDuplicate_Click:
MsgBox Err.Description
Resume Exit_cmdDuplicate_Click

End Sub

Could Someone Help Me In Moving My Record Pointer?
hi there!
i m using data control in my form. when i reach eof moving record pointer to next record, realising eof i try to move it to last record or previous record. but the error message is same all the time... "This operation is cancelled by an associated object"!

I have tried each and every possibility.. including recreating database.. but problem persist..
i m tired of this problem and i give it up to you! would you help me out please?????

Moving To The Last Record - Vsflexgrid Used
im displaying records to the vsflexgrid, im using a view to call the records. i have a button "New" which adds a new row to the grid when pressed. what i want to do is, when i press "new" the cursor will automatically go to the empty row so that i wont have to use the scrollbars just to go down to the empty row.

i display the records in my form_load event

Code:
Set rs = New ADODB.Recordset
Set clsADO = New clsADO

Set rs = clsADO.objBrowse(browser)
Set vsf_library.DataSource = rs

and in my New button:


Code:
vsf_library.Rows = vsf_library.Rows + 1 ' adds an emty row

what shall i add in my "new" button then so that the focus will be in the empty row already?

Moving To Next Record On An Error
Hello everyone. I am writing a program that has 5 nested SQL statements. If the first statement does not return anything, then I get and error right down the line. Is there a may to say on error move to next, loop and continue? Everything I have tried is generating an error or doesn't work. Thanks.

Steve

Movelast Not Moving To Last Record : (
hey all,

I have a confusing problem here and i would greatly appreciate any help, thanks guys :)

ado data controler : adodc1 with text boxes etc bound to this, i can add and update records no problem, but when i go adodc1.movelast it moves to the record precding the one i just added, i close the program and try it again, same story, i can search for records and find them, but i cannot browse to them using movenext or movelast, any ideas??

thanks in advance


Cannot Return To Previous Control
I have written the following vbcode to validate that the user should go to next control until he gives a value for it. But my problem is that using this code I cannot return to the previous control. Please help.

vb code :


Code:

Private Sub cmbMins_Validate(Cancel As Boolean)

If cmbMins.ListIndex = -1 Then
Cancel = True
Else
Cancel = False
cmdGo.SetFocus
End If

End Sub

Determining The Previous Control
Okay, perhaps this is a simple questions, but the answer is certainly eluding me.

In VBA the Screen object has a PreviousControl property, which is very useful if you want to know which control had the focus before the current one received it. In VB, however, the Screen object does not have this property. Does anyone have any ideas how to determine the previous control in VB?

How To Undo Subform After Editing The Previous Or Adding Subform Record????
hi, everyone, im new to microsoft access and stuck there for a long, if i could solve this problem i can procced to other stage. I have a mainform call(Frmfault) and 2 subforms call(subform1) and (ComponentUsed). Each of these forms has their own table. I set the relationships between these tables are " enforce integrity", cascade update and cascade delete.

There are btnAdd(adding record), btnEdit(edit the saved record or adding new record at the subform), btnSave(save the records), btnUndo(undo the changes of the record or added record) and btnClose.

My problem is after i adding the record which 3 forms are blank by clicking the btnadd and i undo by clicking the btnUndo, it is workimg and fine. however aftrer i clicked the btnedit to edit the save records and adding the new records on the subform and clicked the btnundo, it only undo the changes on the mainform but doesn't undo the 2 subforms.

Here is my code :
Code:
for adding button:
Private Sub btnAdd_Click()
Dim mydate As Date
FaultDate.SetFocus
FaultDate = Date

FaultDate.Locked = False
cboSerial.Enabled = True
cboSerial.Locked = False

Dim rst As adodb.Recordset
Set rst = New adodb.Recordset
rst.Open "TerminalFault", CurrentProject.Connection, adOpenStatic, adLockOptimistic

Dim rst1 As adodb.Recordset
Set rst1 = New adodb.Recordset
Dim rst2 As adodb.Recordset
Set rst2 = New adodb.Recordset
rst1.Open "TerminalFaultDetail", CurrentProject.Connection, adOpenStatic, adLockOptimistic
rst2.Open "ComponetUsed", CurrentProject.Connection, adOpenStatic, adLockOptimistic
If rst.RecordCount = 0 Then


DoCmd.GoToRecord , , acFirst
txtRecord = 1
txtRecord = txtTotal
btnAdd.Enabled = False
End If
If rst.RecordCount > 0 Then
If btnEdit.Enabled = False And btnUndo.Enabled = True Then


MsgBox "You are in editing mode at record: " & txtTotal & " " & vbCrLf & " Please save it or undo to unsaved it", vbExclamation, "Status mode"
btnAdd.Enabled = True
Else
DoCmd.GoToRecord , , acNewRec
txtTotal = txtTotal + 1
txtRecord = txtTotal
btnAdd.Enabled = False
End If
End If
btnGotoLast.Enabled = False
Call CheckRecord

End Sub


for edit button:
FaultDate.SetFocus
Dim rst As adodb.Recordset
Set rst = New adodb.Recordset
rst.Open "TerminalFault", CurrentProject.Connection, adOpenStatic, adLockOptimistic

If btnAdd.Enabled = False And rst.RecordCount = 0 Then

MsgBox " There is no record, You can't edit record", vbInformation + vbOKOnly, "Empty record"

Exit Sub

End If

If btnAdd.Enabled = False And btnUndo.Enabled = True Then
MsgBox "Editing mode is unvailable now" & vbCrLf & "You are adding a record at " & txtTotal & "", vbExclamation + vbOKOnly, "Status Mode"
Exit Sub
End If
FaultDate.Locked = False
cboSerial.Enabled = True
cboSerial.Locked = False
FaultNumber.Locked = False

Form_subform1.FaultLinkID.Locked = False
Form_subform1.FaultLinkID.Enabled = True
Form_ComponentUsed.ComponentNumber.Locked = False
Form_ComponentUsed.ComponentQty.Locked = False
Form_ComponentUsed.ComponentNumber.Enabled = True
btnAdd.Enabled = True
btnEdit.Enabled = False


End Sub

for btnundo codes:

If btnEdit.Enabled = False And btnSave.Enabled = True Then
DoCmd.RunCommand acCmdUndo

btnUndo.Enabled = False
btnSave.Enabled = False
btnEdit.Enabled = True
End If

If btnAdd.Enabled = False And txtRecord = 1 Then
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdUndo
btnAdd.Enabled = True
btnSave.Enabled = False
btnUndo.Enabled = False
btnEdit.Enabled = False
FaultDate.Locked = True
cboSerial.Enabled = False
cboSerial.Locked = True
FaultNumber.Locked = True

Form_subform1.FaultNumber.Locked = True
Form_subform1.FaultNumber.SetFocus
Form_subform1.FaultLinkID.Locked = True
Form_subform1.FaultLinkID.Enabled = False
Form_ComponentUsed.ComponentNumber.Locked = True
Form_ComponentUsed.ComponentQty.Locked = True
Form_ComponentUsed.ComponentQty.SetFocus
Form_ComponentUsed.ComponentNumber.Enabled = False
btnUndo.Enabled = False
btnEdit.Enabled = False
Else
If btnAdd.Enabled = False And txtRecord > 1 Then

DoCmd.SetWarnings False
DoCmd.RunCommand acCmdUndo

DoCmd.GoToRecord , , acPrevious
txtRecord = txtRecord - 1
txtTotal = txtRecord
btnAdd.Enabled = True
btnEdit.Enabled = True
btnSave.Enabled = False
btnUndo.Enabled = False
FaultDate.Locked = True
cboSerial.Enabled = False
cboSerial.Locked = True
FaultNumber.Locked = True

Form_subform1.FaultNumber.Locked = True
Form_subform1.FaultNumber.SetFocus
Form_subform1.FaultLinkID.Locked = True
Form_subform1.FaultLinkID.Enabled = False
Form_ComponentUsed.ComponentNumber.Locked = True
Form_ComponentUsed.ComponentQty.Locked = True
Form_ComponentUsed.ComponentQty.SetFocus
Form_ComponentUsed.ComponentNumber.Enabled = False


End If
End If
i also had attached my file, if someone willing to help me and download my file to take a look for it, please download it and go to FmFault, subform1 and ComponentUsed. THank you very, i will appreciate our kindness and helpful. I really need your help.

Moving To Next Record In A Subform Using VBA In A Form?
If I have a regular Access 97 form with no recordset whatsover which merely displays a subform- (the subform of course has a series of records but not the form)? How can I make that subform do a DoCmd.GoToRecord , , acNext using VBA from within the form only?

Moving The Recordset To A Specific Record?
Hey all,

I have a table with a primary key, and the last column of the table stores numbers.

what i want to know how to do is, if i wanted to edit the last column of any particular record, how would I tell the recordset to move to that record by using the primary key as the criteria?

ie. If i wanted to edit the last column (called "seats"), for the record with primary key number 145, how would i do it?



Code:
Dim rs As Recordset
Dim Db As Database

Set Db = OpenDatabase(App.Path & "db1.mdb")
Set rs = Db.OpenRecordset("Flights")

rs. ?????

rs.edit
rs!seats = blablablabla
rs.update
rs.close
db.close

the question marks are where i dont kno wat to do

.MoveNext Isnt Moving To Next Record...
Hey guys/girls:

I am attempting to use .MoveNext for the first time. I am loading the first record to the app on form load, and when you click on the Next button, it should go to the next record and display it. However, it's not displaying anything. It's staying at the first record all the time. Any chance someone can take a look at the attachment and let me know where I am going wrong pls?

Thanks in advance for your help.

Problems With Moving To Next Record In Loop
The code is working fine for the first run through, adding the updating the appropriate fileds but it doesn't work for the other six records or so. Any ideas why?


Code:

Do Until rstBaseTable.EOF

MidTextTel = Mid$(iTelNum, 1, 3)
dtaPaymentTable.Refresh

Set rstPaymentTable = dbsPhone.OpenRecordset("SELECT CallPrice FROM PAYMENT WHERE CallPrefix = '" & MidTextTel & "'")
PriceAsInteger = CSng(txtCallPrice.Text)
Debug.Print PriceAsInteger; "PRICEASINTEGER"

Set rstBaseTableCalc = dbsPhone.OpenRecordset("SELECT Duration " _
& "FROM BASE " _
& "WHERE TelNum Like ' & MidTelText &*';")

dtaBaseTable.Refresh
DurationAsString = CStr(txtDurationBase.Text)
CallCost = PriceAsInteger * DurationAsString

AddCallCost rstBaseTableAdding, CallCost

If rstBaseTable.RecordCount > 0 Then

rstBaseTable.MoveNext

End If

Trying To Stop Moving Past Last Record
I am writing a database with a number of tables with forms atttached to each table. I have placed navigation buttons on each form to move to first, last, next, previous. I have set up the code associated with the buttons as "public sub" so it is available for each form to use.

This was working OK except that when I used the NEXT button at the last record it would open a new blank record & keep opening a new blnak record on each click.

To over overcome this I put in an If statement to check if it had moved to a new record. To do this I used the following:

If Me!NewRecord Then ..... etc

Now I get an error "Invalid use of Me key word" I suspect it is because I am using ME in a public sub

How do I overcome the problem of moving passed the last record and still have the coding available to all forms?


The Code is below.

Thnaks for any help.


Public Sub Next_Record_Click()
On Error GoTo Err_Next_Record_Click

    DoCmd.GoToRecord , , acNext

If Me!NewRecord Then
    ' If new record move back to previous
    DoCmd.GoToRecord , , acNext
    ' Send message
    MsgBox "This is the last record", , "No More Records"
    
End If


Exit_Next_Record_Click:
    Exit Sub

Err_Next_Record_Click:
    MsgBox Err.Description
    Resume Exit_Next_Record_Click
    
End Sub

Moving From One Record To Another In Continous Form
I have a small problem, got a continuos form created by using wizard in Access. One of these field is a checkbox, and are in each row. What I would like to do is to move from Firstrecord to Lastrecord and count for each record if these checkbox field is ticked(true). At the end I would like it prompted to me the number of true checkbox in MsgBox.

Main thing is I don't know how I can get a result for more than one record. Someone please show me a snippet of code to solve this problem, please

How To Utilize Calendar Control To Find Out The Previous Day?
Hi,
I have a Calendar control and I needed previous day with date variable.
Somehow when I use the property it keeps telling me "mismatch..."

Debug.Print frmPPR.Calendar1.PreviousDay



Does anyone know the right way to get the previous date on it?



Thanks a lot!

Parameters From A Previous Page To A Active X Control
HI,
can i, in my activeX, request a parameter i ve launch from the previous page? i like to recieve the number of a client from a login pageand list all this buy... how?
thx a lot

Moving To A Different Record In A Recordset Based On Clicking On A DBLIST
Okay, I have an issue with VB 6.0/DAO 3.51 that I can't get around. I have 2 DBLists that display lists from 2 different fields of the same table that are driven by one SQL query at runtime. I can get the lists to display, but I am having trouble navigating the lists. The operator needs to be able to click on either list and have the other list update to have focus on its specific field of the same record. I initially tried just to select the next item on the list and get the other list to update using the recordset.movenext & recordset.moveprevious methods. I get an error when doing this that says the "Object doesn't support this property or method"

The wierd thing is that the dblists still kind of do what I want after acknowledging the error. I select the item in the list, I get the error, I acknowledge error, then both updates move to the next item in the list. The application doens't crash. I am a bit confused. Here is my code. Thanks, in advance for any assistance.
______________________________________________________
Private Sub DBList2_Click()
Data1.Recordset.MoveNext
End Sub

Private Sub Form_Load()
DBList1.DataField = "ntaID"
DBList1.ListField = "ntaID"
DBList2.DataField = "taskdescription"
DBList2.ListField = "taskdescription"

Data1.RecordSource = "SELECT * FROM nmetls ORDER BY ntaID;"
Data1.Refresh

End Sub
________________________________________________________

Moving To Next Record, And Updating Data Bound Controls
Hey guys,

have a problem. i am forced to use DataEnvionment so dont suggest otherwise. i know it sux.

anyway i have a few controls which is kind of 'data bound' to a recordset in a data environment.

now i want to do a simple record navigation.

like .movenext, etc.

but when i movenext from the Recordset, the DataBound controls doesnt update with the new data. infact, nothing visibly happens.

any suggestions ?

this is the code im using

Private Sub cmdNext_Click()
If DataEnv.rsLect.State <> adStateClosed Then DataEnv.rsLect.Close
DataEnv.rsLect.Open
DataEnv.rsLect.MoveNext
DataEnv.rsLect.Close
End sub


thanks
Deane.

Set Previous Record Of &"A&" As Current Record Of &"B&"
I am making a simple bookkeeping. I need to set the previous value of the "Ending Balance Field" to the current record of the "Opening Balance Field" but I dont know how to. Please help! Urgent!

Max Value Per Record Of Two Field
to all wizards,

is it possible to compare, and get the maximum value of each recordbetween two field?
ex.

Field 1 field 2

record1 = 34 20
record2 = 14 45
record 3 = 20 18




how am i going to arrive at :

34, 45 and 20 as the maximum value of the two field per record.?

can somebody please tell me where to start.it will be a great help.



Anna

Getting The Value Of The Last Row/record Under A Database Field
I have an Oracle database with a table called FILEFOLDER. FILEFOLDER has a field called FILEFOLDERID. I want to access the value of the last record of that particular field and put it into a variable, like shown in the code below:


Code:
strSQL = "SELECT * FROM FILEFOLDER"
RS.Open strSQL, objDB, adOpenForwardOnly, adLockReadOnly

txtFileFolderID = RS!FILEFOLDERID
I don't think the above code is correct, though. I just want to get the value of the last record under FILEFOLDERID...

How To Count Record In A Field
Hallo Hi...
Any body knows the best and the fast way to count or sum the value in a field in a table. Now I'm doing this way to sum value in a recordset:

dim intAmount as long

do while not rs1.EOF
intAmount = intAmount + rs1!Amount
rs1.movenext
loop

if the database become larger and larger, may be the process become slower. Thank you...

Returning A Field Value From A Record
How do I return a value from a particular field in a record. Can I use recordset?

thanks,

Animaul

Copyright © 2005-08 www.BigResource.com, All rights reserved