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 Replies
ADVERTISEMENT
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
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
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
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
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
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 3 Replies
View Related
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
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
Jan 8, 2008
Hi,
I have a form which has a subform. For each record, I have to assign a user, which comes from a user table. Due to the large number of users I have created a user selection form, which is designed as a popup. This form has an option group to select department, which then filters a combo box for selection of a user. On clicking a user, the window closes and that username is inserted into the form.
Since this particular user form will be used in multiple locations, I was thinking of having a global variable, which is set when a field is clicked. i.e. a variable called nameSelect. When a user is being assigned in form A, the user field is clicked, nameSelect = 3.
I was then thinking of having within the user selection form coding a Select Case function which depending on the value of nameSelect assigned the selected user to the correct location.
Is this the best method to tackle this?
View 2 Replies
View Related
Jan 3, 2006
Hi
I just want to ask what is the best method to deliver an application to the user. The reason of asking is that it needs user to have access software installed which is not cheap Any other method that can help, some sort of exe file that can run without access software or atleast something free...
R
View 1 Replies
View Related
Apr 24, 2007
When trying to use FindRecord I get a "Runtime error 2406 - the command or action 'FindRecord" isn't available now". The script up to that point is as follows:
Sub Test()
Dim Connection As New ADODB.Connection
Dim Catalog As New ADOX.Catalog
Dim rstRain As New ADODB.Recordset
Dim ppn_0900 As Field
Set Connection = CurrentProject.Connection
Call rstRain.Open("0800Rain", Connection, adOpenForwardOnly)
DoCmd.FindRecord "10", , False, acDown, , acAll
Can anyone point me in the right direction?
View 2 Replies
View Related
Jun 7, 2005
Hi everyone,
I've recently begun building a database to keep track of stock at work. Nothing particularly special or difficult. I have a little bit of prior experience with Access and VB, but not heaps.
Basically, I've created a tables for parts, companies etc, and am relating all the data together.
At the moment I've made a form that allows you to enter a new part, with Part Number, Description, Category, Supplier, etc.
The complication comes when I want to create an ASSEMBLY of parts. I'd like to create an assembly (which has a lot of similarities to a part, in that it has a part number, description etc), and that assembly needs to store a list of parts that it includes. A simple assembly might include a few items, ie, a bowl of meatballs includes the bowl, a fork, the spaghetti, and 5 meatballs. A more complex assembly (a complete dinner for 5) might include 5 bowls of meatballs (a sub assembly), pepper and salt, 5 glasses and two bottles of coke.
I'm not sure how to best store this assembly data...
I can't really have a table with a finite number of "part" spots because the assemblies get quite large. I'd rather not use an ugly VB macro that stores the PartID's with quantities either, as that could get thoroughly out of hand pretty quickly.
I'm sure there must be a simple method for doing this, but without having a clue as to what it might be called I can't really look for it in help!
Any clues you guys could give me would be great.
Thanks
Col.
View 1 Replies
View Related
Jun 30, 2006
i have set the dropdown method of a combobox in the onfocus event
if then on the click event or exit event for the combobox i validate the entry and find error and move the focus back to the combobox the dropdown method does not appear to work.The focus has clearly been moved away from the combobox but when it returns the dropdown list does not appear
yet it always works the first time you enter the combobox within a form
has anybody else come across this problem!
any solutions
View 1 Replies
View Related
Aug 3, 2006
I want to have my records in my form show the latest entry, not a completely new form. The user will click on the new record button to create a new record but I want the user to be able to see the last record. Anybody know how to do this?
View 14 Replies
View Related
Jan 28, 2007
Hello. I am quite new to Access and even newer to this forum. So please be gentle...
My question is quite simple i think. I want to display one particular record.
I have a keyboard wedge barcode scanner.. so basically a quicker and easier way to input digits or letters into a field. I also have lots and lots of CD's DVD's which i want to track and list the contents of, by simply entering the cd/dvd's barcode number istead of having to insert into my pc and browse manually.. if possible searching within results would be good too.~
think of it as a supermarket style.. input number - output entire contents... there could be hundreds or even thousands of programs or music titles,images, videos or documents.. along with any associated data, (where it is stored, who borrowed it last etc)
Can anbody outline the basics for me to implement this? remember i am quite new to Access and databases in general.
Thanks in advance, and keep up the good work on/in this forum. :)
Rob
View 2 Replies
View Related
Feb 22, 2005
Hi,
I want to be able to make an exact copy of an existing record in a table and then change the value of a couple of the fields before writing it to the table as a new record.
What is the best way to go about this? I guess it is possible with select, update and append queries but I'd rather do it in code.
It sounds like it should be a simple and commonly performed exercise but I can't find anything on it.
Thanks in advance!
John
View 4 Replies
View Related
Apr 17, 2008
quickie -- i am away from my project at the moment - but does the TransferSpreadsheet overwrite existing data ??
i have the transfer set up in to a xls ( this works) but if i change the source will it over write the transfered data (I want it to do this )??
regards
View 2 Replies
View Related
Jun 20, 2005
Hello,
I would like to use the FindRecord Method, but something does not work. I would like to find a record which contains the data I entered in an unbound textbox in the form. The action should be started by a command button. As 'Find what'-object I used '=[text61].[text].
Thanks for your help.
View 2 Replies
View Related
Apr 7, 2005
Hi guys,
I’m working on a report that I want to show on the web as a Snapshot file. I created a Macro using OutputTo method to export the report. If I type the file name and location on the Output File it works perfectly, but the problem is that I want Macros to read the file name from a combo box since the file name will change every day. Here is the code I got so far.
C:Test””&FORMS!frm_FORM2!cbo_Name&”.snp”
Every time I run this Macro I got the following message:
“The report snapshot was not created because you don’t have enough free disk space for temporary work files.”
Now!, when I type the file name to that specific location Macro does the job perfectly.
Is there any way I can get the File name from a combo box located in FORM2.
Thank you so very much in advanced. Your help is always a blessing.
Mosquetero
View 2 Replies
View Related
Sep 27, 2005
Getting an error on the rst.Open statement of
"Method 'Open' of object '_Recordset' failed"
I am using the same code that I have used before, just tweaked some. Earlier I had an error because the ActiveX control was not checked off for the ADODB connection.
Below is the code...any ideas? THANKS!
Dim Conn As ADODB.Connection
Dim rst As New ADODB.Recordset
Dim lg As String
Dim frmOffset As String
Dim tagnm As String
Dim sql1 As String
Set Conn = CurrentProject.Connection
frmOffset = "3. Offset Printing"
lg = "PT"
tagnm = "Label22"
sql1 = "select translation from translation where lang=" & "'" & lg & "'" & "and formname=" & "'" & frmOffset & "'" & " and tagname=" & "'" & tagnm & "'"
rst.Open sql1, Conn, adOpenKeyset, adLockOptimistic
Me.Label22.Caption = rst!translation
View 6 Replies
View Related
Jun 7, 2006
Hi, I want that when a value from combo box is selected, based on it the values in the text box should appear. These are all bound columns.
I have written the following code and getting as error "Run time Error 3075" syntax error "missing operator" in query operation at line - >Set rs = db.OpenRecordset(strSQL) in the following code appears. Please help.
Private Sub Assigned_To_LostFocus()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Assigned_To.SetFocus
If Assigned_To.Value > 0 Then
strSQL = "SELECT * FROM Department WHERE Assigned To = " & Assigned_To.Value
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)
If Not rs.BOF Then
Me.Text65 = rs.Fields(1) / Me.Text65 = rs("code")
Me.Department = rs.Fields(2) / Me.Department = rs("Department")
End If
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
End If
End Sub
View 2 Replies
View Related
Aug 2, 2006
To save records in a form, close the form and open a switchboard, I have the following Event code on clicking a command button on the form:
'Command on last page to save records and go to Switchboard
Private Sub OpenSwitchboard_Click()
On Error GoTo Err_OpenSwitchboard_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.Close acForm, "CaseNotes", acSaveYes
DoCmd.OpenForm "frmSwitchboard"
Exit_OpenSwitchboard_Click:
Exit Sub
Err_OpenSwitchboard_Click:
MsgBox Err.Description
Resume Exit_OpenSwitchboard_Click
End Sub
This seems to work okay in Access 2000, but I understand the DoMenuItem method is obsolete, and that I should replace "DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70" to a RunCommand method, but I am not sure about this.
I would be grateful for any help in replacing this piece of DoMethod code with RunCommand code! mcchu
View 4 Replies
View Related
Jun 18, 2014
Is there a way of finding out who is turning18 years old in the next 6 months on a set day.
Specifically, I want to minus a date of birth from todays date (DateDiff?) and then for it to show those people who will be turning 18 in the next 6 months.
I've tried a range of Datediffs but I can't seem to get what I need.
View 11 Replies
View Related
Apr 6, 2006
Hi
I am new to VB.
Can anyone tell me what the 'ac' part of a method, such as 'acReport', actually means. I am guseeing it may be something like Active Command or similar.
There is no other reason that curiosity for me wanting to know this...or is there??
Thanks in advance
View 1 Replies
View Related
Apr 13, 2007
Hi,
I want to disable a button right after click it. Because I could not disable a control that has got the focus, i tried to shift the focus to another control; however, all controls that I tried to shift the focus to don't support the method (SetFocus = true).
I want to do this on a subform's control, but I keep getting this error:
Object does not support this property or method.
Any susggestions will be very much appreciated.
B:)
View 3 Replies
View Related