Rst.FindFirst Problem

Mar 2, 2005

Hello All

I just discovered the reason why my table has not been working the way I want it to. In my code below, I have set my rst to find the first record of the previous month which in itself is correct, however I just discovered that it is picking up the records in ascending order.

Here is my code:
Option Compare Database
Option Explicit

Private Sub Button5_Click()

Dim prevMonth As Integer
Dim curMonth As Integer
Dim prevYear As Integer
Dim curYear As Integer
Dim CurRecordMonth As Integer
Dim rst As Recordset
Dim rst2 As Recordset
Dim db As Database
Dim monthText As Variant

Set db = CurrentDb

'fill an array with the text for months names
monthText = Array("", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")

' find previous and current Year and month. If current month = jan then go back to Dec of the year before
curMonth = Month(Date)
curYear = Year(Date)
prevYear = Year(Date)
prevMonth = Month(Date) - 1

If prevMonth = 0 Then
prevMonth = 12
prevYear = prevYear - 1
End If

' count number of existing records for current year and month
' If DCount("Month", "TTransactions", "month = '" & monthText(curMonth) & "' and year = " & curYear) = 0 Then

If DCount("Month", "tTransactions", "month = " & curMonth & " and year = " & curYear) < 2 Then
'if current month and year does not exist in table
' open table and find last months record
Set rst = db.OpenRecordset("tTransactions", dbOpenDynaset)
rst.FindFirst "month = " & prevMonth & " and year = " & prevYear
' open table again to write a new record
Set rst2 = db.OpenRecordset("tTransactions", dbOpenDynaset)
Do Until rst.NoMatch ' loop through all records meeting the criteria
rst2.AddNew
rst2![TelNo] = rst![TelNo]
rst2!Year = curYear
rst2!Month = curMonth
rst2!Rental = rst!Rental
rst2![Fees] = rst![Fees]
rst2![Vat] = rst![Vat]
rst2.Update
rst.FindNext "month = " & prevMonth & " and year = " & prevYear
Loop
rst.Close
rst2.Close
Set rst = Nothing
Set rst2 = Nothing
End If
Set db = Nothing

End Sub

Function CallButton5()

Call Button5_Click

End Function


I have put in an autonumber to assign sequential numbers to the records as they are entered. This I had hoped would allow me to sort my query by autonumber, however if the findfirst keeps finding the records in ascending order then I'm lost. Is there any way to get round this?

Thank you Kindly

View Replies


ADVERTISEMENT

MySQL & FindFirst

May 9, 2005

Hello,
I hope I have posted this to the correct forum?
Anyways, I have started porting my database backend to MySQL after a spate of corruptions and speed degrading daily, I have managed to get most things functional but one thing which I can not get working is an odd thing with the FindFirst statement.
I have the following line of code...

rst2.FindFirst "AwaitingStock=True and StockIn=False and DOA=False and Model='" & Trim(Me.Model) & "'"

which works find with Access backend but with MySQL I get the error...

Run-time error '3761':
The decimal field's precision is too small to accept the numeric you attempted to add.

This is obviously not the correct error as I am not trying to add anything!
If I remove the bit about the Model, the code executes fine, also, if I remove all the =True parts and just leave the Model part everything works fine so I guess it is because I am mixing string and integer fields in the search???

Any help greatly appreciated.


Kind regards,


Tom Findlay

View 2 Replies View Related

Listbox FindFirst

May 1, 2006

When, id do press the 'RecordWeergeven' button, Microsoft Visual Basic returns with a error. Method or data member not found. I think the error is located bij Me.Keuzelijst0. Do i have to declare a Listbox or create a second recordset. Please help.

Private Sub RecordWeergeven_Click()
'Me.RecordsetClone.Findfirst "[ID] = " & Me.lstList.ItemData(lstList.ListIndex)
'Me.Bookmark = Me.RecordsetClone.Bookmark
Dim rst As ADODB.Recordset
Set rst = Forms![FMR_users].RecordsetClone
rst.FindFirst "usr_id=" & Me.Keuzelijst0 & ""
Forms![FMR_users].Bookmark = rst.Bookmark
DoCmd.Close acForm, "GaNaarRecord"
End Sub

View 3 Replies View Related

Syntax Help On Rs.findfirst

Mar 25, 2008

Hi, I need some syntax help on the following line of code:

rs.FindFirst (rs![NewRecord] = True And IsNull(rs![Event_No]))

where NewRecord is type boolean and Event_No is string. Ive used this function mainly on strings so am not sure what to do with this one!
thanks!!

View 2 Replies View Related

Using The FindFirst Method With DAO

Aug 1, 2005

I am writing an event procedure to check to see if a particular Project number exist in a recordset. I am trying to use the findfirst method and are having some problems. Here is my code.

Private Sub Command3_Click()

Dim db As DAO.Database
Dim rs As DAO.Recordset, ProjectNo As String, SqlStr As String, StrProjectNo As String


Set db = CurrentDb()
Set rs = db.OpenRecordset("tblTrackingSheetFrm", dbOpenTable)
StrProjectNo = Me![ProjectNumber]
rs.FindFirst StrProjectNo

If rs.NoMatch Then
Forms![frmProjectCriteria].Visible = False
DoCmd.SetWarnings WarningsOff
DoCmd.OpenQuery "(1)qryDeletetblTrackingSheetFrm"
DoCmd.OpenQuery "(1A)qryDeletetblTrackingSheetTMP"
DoCmd.OpenQuery "(2)qryAppendProjectTasks"
DoCmd.OpenQuery "(3)qryMaketblLaborActuals"
DoCmd.OpenQuery "(3A)qryUpdatetblTrackingSheetTMP"
DoCmd.OpenQuery "(4)qryDeletetblMaterialActualsTMP"
DoCmd.OpenQuery "(5)qryAppendEquipment"
DoCmd.OpenQuery "(6)qryAppendInventory"
DoCmd.OpenQuery "(7)qryAppendPayables"
DoCmd.OpenQuery "(8)qryAppendPurchaseOrder"
DoCmd.OpenQuery "(9)qryUpdateMaterialActuals"
DoCmd.OpenQuery "(A)qryAppendtblTrackingSheetFrm"

DoCmd.SetWarnings WarningsOn
DoCmd.OpenForm "frmTrackingSheet", acNormal

Else

MsgBox " Project worksheet already opened by another user."

rs.Close
End If
End Sub

What this does is check to see if another user has a project open and if so doesnt allow that user to access that project. I am getting the following error when I execute the procedure on the findfirst Code line.

Runtime error 3251 Operation is not supported by this object type.
Can someone take a look and see what I am doing wrong.
Any help is greatly appreciated.

View 2 Replies View Related

Recordset - FindFirst Issues

Feb 23, 2005

Hello,

I have a procedure that searches a table (recordset 1) for values in a lookup table (recordset 2) using FindFirst / FindNext. The routine worked fine until recently, I now have two issues;

I have included a new country in the lookup table - Cote D'Ivoire, now I get an error message when it reaches this name. I guess it's the " ' " that is causing the problem but don't know how to get round it!!??

I have modified the program so I can select the field I want to search from a form (thanks John) but it won't accept the field name as it's not part of the recordset e.g. rstTempTable.findfirst "[Field] = etc. How can I pass the chosen field from the form to the recordset?


Thanks in advance .....

View 4 Replies View Related

Bookmarking Recordsets FindFirst

Sep 27, 2005

Need a little help with a record selector.
I ask it to find a record and bookmark it. No problem.
If record doesnt exist I get the value from a control and run a Insert Into command into my table creating a new record with that case #.

Now how do I modify the code below to make the new record just inserted into the bookmarked record. See sample code below. I'm not too practiced when it comes to this recordset business.

Any help is appreciated



Private Sub FindTheRecord()
' Find the record that matches the control.
Dim rs As Object
Dim Answer As String
Dim aSQL As String

Set rs = Me.Recordset.Clone
rs.FindFirst "[CaseNo] = " & Str(Nz(Me![CaseNo]))
If rs.NoMatch Then
Answer = MsgBox("No Matching Case Number Found." & vbCrLf & "Would you like to start a new" & vbCrLf & "record using this case number?", vbYesNo)
If Answer = 6 Then
DoCmd.SetWarnings False
aSQL = "Insert Into Main ([CaseNo])Values ([Forms]![frmMain]![CaseNo]);"
DoCmd.RunSQL aSQL
DoCmd.SetWarnings True

DoCmd.GoToRecord acDataForm, "frmMain", acLast
Code: Original - Code ' does not recognize the last record just added to the table, is there a command I can use here? ' does not recognize the last record just added to the table, is there a command I can use here?

Else
MsgBox "Action Cancelled"
CaseNum = ""
CaseNumYear = ""
DoCmd.GoToControl "CaseNum"
End If
Else
Me.Bookmark = rs.Bookmark
Call EnableControls
End If
End Sub

View 3 Replies View Related

Queries :: Proper Syntax For FindFirst Method

Nov 15, 2013

I can't seem to figure out the proper syntax for the FindFirst method. I am using several variations of this effort:

Dim dbs As dao.Database
Dim rst As dao.Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblInvoice", dbOpenDynaset)
rst.FindFirst "rst!ID = frmInvoice!txtID"

I get an error message that says that Access doesn't recognize rst.ID as a valid field. But, it most certainly is. I tried substituting tblInvoice but got the same error.

View 3 Replies View Related

Forms :: Locate A Record On Multirecord Form By Using Findfirst Method

Mar 8, 2014

I am trying to locate a record on a multirecord form by using Findfirst method. Here is the code.

Dim UA1 As String, UAE1 As String, UA2 As String, UAE2 As String, UA3 As String, UAE3 As String, apost as string, repl as string
apost = "'"
repl = "''"
UA1 = Nz(Forms(ParName).Form.NAME, " ")
UAE1 = Replace(UA1, apost, repl)

[Code] ....

This code sometimes works and sometimes it does not work. The field CNO is a text field of 5 characters but contains the card numbers that is numeric data or nothing.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved