I tried to get help elsewhere with this but it didn't quite work out, so I thought I'd pick a few other brains. So here's the problem from the beginning.
I made a table with three fields:
Field Name----Data Type
Category------Text
Item----------Text
Cost----------Number
I set up a form with two combo boxes and two text boxes. I want to pick an Item from the combo box, and have the Cost appear in the corresponding text box. I set up the combo box to show each field when I click on the arrow.
I was given the following code to put in the After Update section under the Event tab for the combo box:
Private Sub Combo8_AfterUpdate()
Me.Text2 = Me.Combo8.Column(2)
End Sub
That works. I pick an item from the combo box, and its value appears in the text box next to it. Ultimately, I want to edit the value in the text box and have it update the table. I was given the following code for the text box:
Private Sub MyTextbox_AfterUpdate()
Dim strSQL As String
strSQL = "UPDATE MyTable " & _
"SET Myfield = " & Me.MyTextbox & _
" WHERE Id = " & Me.MyCombo
CurrentDb.Execute strSQL, dbFailOnError
End Sub
So far, that hasn't worked. I believe I've made the correct substitutions:
Private Sub Text2_AfterUpdate()
Dim strSQL As String
strSQL = "UPDATE [Primary Table] " & _
"SET Cost = " & Me.Text2 & _
" WHERE Id = " & Me.Combo8
CurrentDb.Execute strSQL, dbFailOnError
End Sub
When I type a different value into the text box and hit enter, I get the following error:
Run-time error '3061':
Too few parameters. Expected 2.
I was given a different line of code in the event that I'm "trying to pass text":
" WHERE Id = '" & Me.Combo8 & "'"
When I use that, the error is the same except it says:
I am trying to open a recordset object using a reasonably complex query. The query uses other queries to get data and some of these queries are totaliser queries (I dont know the proper terminology but they are the ones that group and sum up data in the query).
Dim D As Database, R As Recordset, R2 As DAO.Recordset Set D = DBEngine.Workspaces(0).Databases(0) Set R2 = D.OpenRecordset("Qry Daily Losses", dbOpenSnapshot)
The error Message I get is:
Run-time error "3061" Too few parameters. Expected 4.
Most of the information I have seen on this error message talks about 1 parameter expected not 4.
I can open the query directly by clicking on it in the objects list and it looks fine. It is only when I try to open it in my code that it goes wrong.
I have a error I need help with. Here is my code for my Global, and My Form Current: See the red for the Error Line, that show up in the VBE and the Blue is the code related to that line. I am using access 2003
'Declare all variables for right-side record counter Dim bdg As DAO.Recordset Dim swr As DAO.Recordset Dim wtr As DAO.Recordset Dim dmo As DAO.Recordset ''Dim dvt As DAO.Recordset Dim occ As DAO.Recordset Dim fre As DAO.Recordset Dim swrlat As DAO.Recordset Dim wrtlat As DAO.Recordset
Dim bdgCount As Integer Dim swrcount As Integer Dim wtrcount As Integer Dim dmocount As Integer Dim dvtcount As Integer Dim occcount As Integer Dim frecount As Integer Dim countswr As Integer 'laterial counter Dim countwtr As Integer 'laterial counter
Dim sqlbdg As String Dim sqlswr As String Dim sqlwtr As String Dim sqldmo As String ''Dim sqldvt As String Dim sqlocc As String Dim sqlfre As String Dim sqlswrlat As String Dim sqlwtrlat As String
Dim db As DAO.Database
Private Sub Form_Current() Set db = CurrentDb() 'Use SQL strings to pull data from the tables sqlbdg = "SELECT [Building].[PIN] FROM Building WHERE [Building].[PIN]='" & Me![ADDRESS3] & "' ;" sqlswr = "SELECT [Sewerform].[PIN] FROM [SEWER SERVICE LATERALS] WHERE [Sewerform].[PIN]='" & Me![ADDRESS3] & "' ;" sqlwtr = "SELECT [water].[PIN] FROM [WATER SERVICE LATERALS] WHERE [water].[PIN]='" & Me![ADDRESS3] & "' ;" sqlswrlat = "SELECT [SewerMain].[PIN] FROM [SEWER MAIN PRBLEMS] WHERE [SewerMain].[PIN]='" & Me![ADDRESS3] & "' ;" sqlwtrlat = "SELECT [WaterMain].[PIN] FROM [WATER MAIN PROBLEMS] WHERE [WaterMain].[PIN]='" & Me![ADDRESS3] & "' ;" sqldmo = "SELECT [Demolition Permits].[PID] FROM [Demolition Permits] WHERE [Demolition Permits].[PID]='" & Me![ADDRESS3] & "' ;" ''There is no PIN field in the development table ==> sqlwtr = "SELECT [Development Permits].[PIN] FROM [Development Permits] WHERE [Development Permits].[PIN]='" & Me![ADDRESS3] & "' ;" sqlocc = "SELECT [Occupancy].[PIN] FROM Occupancy WHERE [Occupancy].[PIN]='" & Me![ADDRESS3] & "' ;" sqlfre = "SELECT [Freeze].[PIN] FROM Freeze WHERE [FREEZE].[PIN]='" & Me![ADDRESS3] & "' ;"
Set bdg = db.OpenRecordset(sqlbdg, dbOpenSnapshot) Set swr = db.OpenRecordset(sqlswr, dbOpenSnapshot) Set wtr = db.OpenRecordset(sqlwtr, dbOpenSnapshot) Set dmo = db.OpenRecordset(sqldmo, dbOpenSnapshot) ''Set dvt = db.OpenRecordset(sqldvt, dbOpenSnapshot) Set occ = db.OpenRecordset(sqlocc, dbOpenSnapshot) Set fre = db.OpenRecordset(sqlfre, dbOpenSnapshot) Set swrlat = db.OpenRecordset(sqlswrlat, dbOpenSnapshot) Set wrtlat = db.OpenRecordset(sqlwtrlat, dbOpenSnapshot)
'Building recordset On Error Resume Next If bdg.EOF And bdg.BOF = True Then bdgCount = 0 Else
With bdg .MoveFirst .MoveLast bdgCount = .RecordCount End With
End If
'Sewer recordset On Error Resume Next If swr.EOF And swr.BOF = True Then swrcount = 0 Else
With swr .MoveFirst .MoveLast swrcount = .RecordCount End With
End If
'Water recordset On Error Resume Next If wtr.EOF And wtr.BOF = True Then wtrcount = 0 Else
With wtr .MoveFirst .MoveLast wtrcount = .RecordCount End With
End If 'Sewer laterial recordset On Error Resume Next If swrlat.EOF And swrlat.BOF = True Then countswr = 0 Else
With swrlat .MoveFirst .MoveLast countswr = .RecordCount End With
End If
'Water laterial recordset On Error Resume Next If wrtlat.EOF And wrtlat.BOF = True Then countwtr = 0 Else
With wrtlat .MoveFirst .MoveLast countwtr = .RecordCount End With
End If
'Demolition recordset On Error Resume Next If dmo.EOF And dmo.BOF = True Then dmocount = 0 Else
With dmo .MoveFirst .MoveLast dmocount = .RecordCount End With
End If
'Development recordset ''On Error Resume Next ''If dvt.EOF And dvt.BOF = True Then dvtcount = 0 ''Else
Hello Access friends, What is wrong with the following code (modified the module from http://members.iinet.net.au/~allenbrowne/AppInventory.html ): I Keep getting a runtime error 3061 Too few parameters . Expected 1 on the line highlight below. I have the reference MS DAO 3.6 selected and I am using access 2000 and calling the module from a command button in a form. Thanks in advance for taking the time to help me out.
Dim db As DAO.Database 'CurrentDb() Dim rs As DAO.Recordset 'Various recordsets. Dim strProduct As String 'vProductID as a string. Dim strAsOf As String 'vAsOfDate as a string. Dim strSTDateLast As String 'Last Stock Take Date as a string. Dim strDateClause As String 'Date clause to use in SQL statement. Dim strSQL As String 'SQL statement. Dim lngQtyLast As Long 'Quantity at last transaction. Dim lngQtyAcq As Long 'Quantity acquired since incoming transaction. Dim lngQtyUsed As Long 'Quantity used since outgoing transaction.
If Not IsNull(vProductID) Then 'Initialize: Validate and convert parameters. Set db = CurrentDb() strProduct = vProductID If IsDate(vAsOfDate) Then strAsOf = "#" & Format$(vAsOfDate, "mm/dd/yyyy") & "#" End If
'Get the last transaction date and quantity for this product. If Len(strAsOf) > 0 Then strDateClause = " AND ([TransacDate] <= " & strAsOf & ")" End If strSQL = "SELECT TOP 1 [TransacDate], [Quantity] FROM [Transactions] " & _ "WHERE ((ProductID = " & strProduct & ")" & strDateClause & _ ") ORDER BY TransacDate DESC;"
Set rs = db.OpenRecordset(strSQL) With rs If .RecordCount > 0 Then strSTDateLast = "#" & Format$(![TransacDate], "mm/dd/yyyy") & "#" lngQtyLast = Nz(!Quantity, 0) End If End With rs.Close
'Build the Date clause If Len(strSTDateLast) > 0 Then If Len(strAsOf) > 0 Then strDateClause = " Between " & strSTDateLast & " And " & strAsOf Else strDateClause = " >= " & strSTDateLast End If Else If Len(strAsOf) > 0 Then strDateClause = " <= " & strAsOf Else strDateClause = vbNullString End If End If
'Get the quantity acquired since then. strSQL = "SELECT Sum([Transactions].[Quantity]) AS QuantityAcq " & _ "FROM [Transactions]" & _ "WHERE (([Transactions].[ProductID] = " & strProduct & ") AND ([Transactions].[TransacType] = 'Incoming')" If Len(strDateClause) = 0 Then strSQL = strSQL & ");" Else strSQL = strSQL & " AND ([Transactions].[TransacDate] " & strDateClause & "));" End If
Set rs = db.OpenRecordset(strSQL) If rs.RecordCount > 0 Then lngQtyAcq = Nz(rs!QuantityAcq, 0) End If rs.Close
'Get the quantity used since then. strSQL = "SELECT Sum([Transactions].[Quantity]) AS QuantityUsed " & _ "FROM [Transactions]" & _ "WHERE (([Transactions].[ProductID] = " & strProduct & ") AND ([Transactions].[TransacType] = 'Outgoing')" If Len(strDateClause) = 0 Then strSQL = strSQL & ");" Else strSQL = strSQL & " AND ([Transactions].[TransacDate] " & strDateClause & "));" End If
Set rs = db.OpenRecordset(strSQL) If rs.RecordCount > 0 Then lngQtyUsed = Nz(rs!QuantityUsed, 0) End If rs.Close
'Assign the return value OnHand = lngQtyLast + lngQtyAcq - lngQtyUsed End If
Set rs = Nothing Set db = Nothing Exit Function End Function
Hello. I am trying to sort this out and hope someone can help.
Using Access 2002 front end, sqlserver 2000 back end.
In my front end database I have a query called "queEEGBilling" that is used to populate a report. It is quite a complex query which I did using the query designer, NOT with a WHERE sql command. I am not very good with SQL syntax.
The report works fine, and displays the records I want it to display.
However, after the report is displayed, I want to modify one field in each record to indicate that the report for hat record has been printed out (it is a billing package, and I want to indicate that the bill has been sent).
In order to do this, I need to access the recordset that was used to create the report. As I understand it, I cannot do this with a report (no equivalent of the recordsetclone property or anything similar). What I have to do is create the recordset that was used to create the report in the first place. No problem right?
set mydb=dbengine(0)(0) set rs1=mydb.openrecordset("queEEGBilling")
However, here I get the infamous error 3061. Too Few Parameters. Expected 1.
I have googled this up and down, and it seems to be related to my query being too complex. However, I did not write this query by hand, it came from Access2002. And this query worked fine to generate my report. So, why does it crash now??
I am running this code, and i am getting this error:
Code:Private Sub SendFormToConsultants_Click() On Error GoTo Err_SendFormToConsultants_Click Dim stWhere As String '-- Criteria for DLookup Dim varTo As Variant '-- Address for SendObject Dim stText As String '-- E-mail text Dim stSubject As String '-- Subject line of e-mail Dim stCOFNumber As String '-- The COF Number from form Dim stCustomerID As String '-- The Customer ID from form Dim stCompanyName As String '-- The Company Name from form Dim stContactName As String '-- The Contact Name from form Dim stAddress As String '-- The Company Address from form Dim stTRDW As String '-- The TRDW from form Dim stPreReq As String '-- The PreReq from form Dim stWorkLoc As String '-- The Location of Work from form Dim stDelivActiv As String '-- The Deliverables/Activities from form Dim stStartDate As Date '-- The Start Date from Subform Dim stEndDate As Date '-- The End Date from Subform Dim stWho As String '-- Reference to Resources Dim strSQL As String '-- Create SQL update statement Dim errLoop As Error '-- Combo of names to assign COF to stWho = Me.COF_Scheduled__Assigned_Resources__Subform1!Res ourceName stWhere = "Resources.ResourceName = " & "'" & stWho & "'" '-- Looks up email address from Resources varTo = DLookup("[ResourceEmail]", "Resources", stWhere) stCOFNumber = Me!COFNumber stCustomerID = Me.Consultancy_Order_Form_CustomerID stCompanyName = Me.CompanyName stContactName = Me!COFContact stAddress = Me.Address stTRDW = Me.TRDW stPreReq = Me.PreRequisites stWorkLoc = Me.WorkLocation stDelivActiv = Me.DeliverablesActivities stStartDate = Me.COF_Scheduled__Assigned_Resources__Subform1!Sta rtDate stEndDate = Me.COF_Scheduled__Assigned_Resources__Subform1!End Date stSubject = ":: New Consultancy Order Assigned ::" stText = "You have been assigned a new Consultancy Order." & vbCrLf & _ "Consultancy Order Form Number: " & stCOFNumber & _ vbCrLf & _ "Company ID: " & stCustomerID & _ vbCrLf & _ "Company Name: " & stCompanyName & _ vbCrLf & _ "Contact Name: " & stContactName & _ vbCrLf & _ "Address: " & stAddress & _ vbCrLf & _ "Terms of Reference / Description of Work: " & stTRDW & _ vbCrLf & _ "Pre-Requisites: " & stPreReq & _ vbCrLf & _ "Location of Work: " & stWorkLoc & _ vbCrLf & _ "Deliverables / Activities: " & stDelivActiv & _ vbCrLf & _ "Start Date: " & stStartDate & _ vbCrLf & _ "End Date: " & stEndDate & _ vbCrLf & _ "Please reply to confirm Consultancy Order Assignment." 'Write the e-mail content for sending to Consultant DoCmd.SendObject , , acFormatTXT, varTo, , , stSubject, stText, -1 'Set the update statement to disable command button once e-mail is sent strSQL = "UPDATE [Consultancy Order Form] SET [Consultancy Order Form].COFSentToConsultants = 0 " & _ "Where [Consultancy Order Form].COFNumber = " & Me!COFNumber & ";" On Error GoTo Err_Execute CurrentDb.Execute strSQL, dbFailOnError On Error GoTo 0 'Requery checkbox to show checked 'after update statement has ran 'and disable send mail command button Me!COFSentToConsultants.Requery Me!COFSentToConsultants.SetFocus Me.SendFormToConsultants.Enabled = False Exit SubErr_Execute: ' Notify user of any errors that result from ' executing the query. If DBEngine.Errors.Count > 0 Then For Each errLoop In DBEngine.Errors MsgBox "Error number: " & errLoop.Number & vbCr & _ errLoop.Description Next errLoop End If Resume NextExit_SendFormToConsultants_Click: Exit SubErr_SendFormToConsultants_Click: MsgBox Err.Description Resume Exit_SendFormToConsultants_ClickEnd Sub
What does it mean? it doesn't say where i have a problem in my code. What do you think?
Not sure how to work in the '* ROLL *' into this SQL statement. The query statement works fine ... I have tried different quotation methods ( Not Like " & " ' * ROLL * & ' " & " ) AND .... )
sql = "SELECT DISTINCTROW Sum(CDbl([Scrap Factor])) AS SumOFScrap FROM [RT: Signpro1: Costs] LEFT JOIN [DT: InventoryExtend] ON [RT: Signpro1: Costs].[Part Number] = [DT: InventoryExtend].[Part#] GROUP BY [DT: InventoryExtend].CategoryID, [DT: InventoryExtend].Description, [forms]![signpro sign estima parameters]![combo14] HAVING ((([DT: InventoryExtend].CategoryID)=30) AND (([DT: InventoryExtend].Description) Not Like '* ROLL *') AND (([forms]![signpro sign estima parameters]![combo14])=1));"
I have been struggling with getting the syntax right for the ConcatRelate function. I have looked at other peoples examples and mine seems to have exactly the same syntax but it is giving me an error.
My Sql is
SELECT qr_RiverGroup.River, ConcatRelated("Site_ID","qr_RiverGroup","[River] = '" & [River] & "'") AS Expr1 FROM qr_RiverGroup;
I have a library function that will allow the user to nominate a query (as one of its arguments) in the calling application which must have an email field. The function will then Do Loop the email field, concatenating it before creating an email and addressing it. The intended functionality is that a developer can easily create a group email, just by creating a query.
This works fine if the query is filtered "statically" - i.e. I specify which group of people by typing in their "Site_ID" in the criteria. However I want developers to be able to creating dynamically filtered queries (perhaps by the group's ID on a calling form). Within the query (to test it), the filter is therefore [Forms]![Test Function Calls]![Site_id]. When I run the code, I am then presented with "Run-time error 3061: Too few parameters. Expected 1". The code in question is:
Dim rst As DAO.Recordset Dim stTo As String 'one of the function's arguments received from the calling function. Dim stToString As String 'the built up concatenated emails
Set rst = CurrentDb.OpenRecordset(stTo, dbOpenDynaset, dbSeeChanges)
I'm creating a simplified timecard entry form, and everything works perfect except one thing. When I start a new record and go to the subform and choose the day (monday - friday) it says "This property is read-only and cannot be set" but then it goes ahead and accepts the entry.
A little background, I am making the times as simplified entry (100 for 1pm, 800 for 8am, 500 for 5pm) no colons will be entered. Our hours of operation are roughly 7am until 630pm, with the occassional clock in before 6am and clock out up until 8pm or so. I have this error checking in place, it works ok, I add 1200 to the time if it is pm. Now if they are making a straight time adjustment, they enter it in as well.... for instance 8 for 8hrs holiday pay or paid time off. All this stuff works, that's not the problem.
I am thinking, maybe it might have something to do with having 4 or 5 fields set as the combined primary key on the table that holds the time/adjustment data. The reason I did the combined primary key is so they could enter in the same name, the same start date, even the same day, but the adjustment/time value has to be unique when it is compared with the start date, name, day, adjustment/time value. This table is the subform.
The weird thing is, that after the error, it lets the value stand and does not show the error again, as long as you are on this recordset. If I go back into that record and start a new entry below the others, I get the error again. While the error has no detrimental effects on the db, it is annoying.... and it still shows if I run the form off a macro with setwarnings to false.
I am including the database for review for those of you brave enough to try to understand my logic I'm sure it's something simple. I don't see anything in the properties for the form to turn off error messages like you can in data access pages, or maybe I just overlooked it. I have left one recordset in to show the functionality, it all works according to plan. This is just a rudementary database, I will fine tune it after I get past this hurdle.
Edit: I have Calendar control 11.0 for the start date, but this isn't the problem as it still did it when I had the actual field showing. That, and if you see the disparity between hours and minutes and paid time, it's because if they worked so many hours, 1/2 hour is automatically subtracted. Which is why there is a lunch adjustment field.... if they didn't take a lunch or if they took too long of a lunch.
I have designed a form to act as a menu to open other forms. I created the form and placed command button on the form. Using the Access Wizard, the following VBA was created by Access to open the next form:
Private Sub cmdCCDolClr_Click() On Error GoTo Err_cmdCCDolClr_Click
Dim stDocName As String Dim stLinkCriteria As String
I have done this several times in the past with success. However, this time, I get the following error message when I click on the command button to open the second form.
The expression On Click you entered as the event property setting produced the following error: A problem occured while GCM (name of dB) was communicating with the OLE server or Active X Control. *The expression may not result in the name of a macro, the name of a user-defined function, or [EVENT PROCEDURE]. *There may have been an error evaluating the function, event or macro.
I tested other forms that were designed to open secondary forms and they continue to act correctly. Is there an easy fix to this issue. There are 16 command buttons and all get this message. Do I have to delete the form and recreate it. A nusiance, but not difficult.
Looking forward to hearing from you experts out there. Thanks, Alan __________________ Alan Sidman
when i want to open the database in an access database i have the following error. you have as the event property setting the expression entered when open.This expression has caused an error amppu (database name) can not find the form that is referred to
I'm creating a DB that includes a form that "Customers" will fill out. The form (CustomerForm) has text boxs that must be completed. I'm trying to figure out how to make sure all text boxes are filled out. I have already created a Input Mask and selected Required in the "Customer" Table. There is also a Username text box I would like to have validated that is is not already being used and two password text boxes I would like to have validate against one another to ensure it was created correctly. Once all text boxes are properly filled out I would like the Button to Save customer data, close CustomerForm and Open ShoppingCart. This is the code I have created:
Code: Option Compare Database Private Sub Log_In_Click() If IsNull(Me.CustomerFName) Then MsgBox "Please Enter First Name", vbInformation, "First Name Required" Me.CustomerLName.SetFocus
I have a form designed to execute a query with a prompt for a particular record. When the record being searched for is not there the form become blank with nothing on it. I would like to return a message that indicates that the record was not found and give he user an option of reexecuting the query of exiting the form.
I have 5 check boxes on a form and one of them must be checked in order to get the correct result. If the user does not check any of the the five checkboxes he gets a msgbox telling him that he must checks one of the checkboxes.
What i want to ask is if is possible to prevent the form from updating? Because the user gets the error message but after that the form is being updated even though he hasn't check any of the fields.
I have created a profiling form for my school. Each boy can access his form using his admission number ( Adno) which is the primary key. On the form are lots of sub forms - for things like favourite authors, clubs, teams played in etc - but these don't have a primary key ( as they are automatically linked to the Adno via the main form ). Unfortunately when several boys are filling in their own forms at the same time I keep getting error messages, one says that the data can't be updated and another says that there is a primary key problem.
I have a form and when it's opened you get 3 different search questions to answer or leave blank. My question is.... If a search parameter is entered but no results are found to match it, how do I create an error message telling the requestor "No Data Found"?
I have a form with a subform in it. On the main form, I have a combo box with a list of program numbers to choose from. Once one is selected, the subform displays all the unpaid invoices under that program number. This part works fine. The problem occurs when I try to close the form, switch to design view, or scroll the subform to the right. Basically, the error message says that the record can't be saved because it would create a duplicate value in the index/primary key. However, this form is used to display information only. I have disabled the edit, delete and addition abilities, so I can't figure out why it thinks I am trying to change or add a new record. Any help would be appreciated.
I figured it might make things easier if I included a copy of the database, so here it is.
The form is called SETR, and the subform is AllInfo subform.
Does anybody know what this error message refers to?
"Reserved Error (-1517); there is no message for this error."
It just started happening today, and I haven't even made any changes to the database. It occurs when I hit a button I have to run a macro.
the macro does the following: 1) Shows all records 2) Requery 3) ApplyFilter. The Where Condition for the filter is: Right([tblContracts].[JobNum],4)=Right([Forms]![FrmContProc].[txtFindJobNum],4)
The weird thing is that it only occurs if the Form window is taller than 1/2 of my viewable area. If the Form window is 1/2 the viewable area or shorter, it works OK. This was running fine earlier today, but about 4:00 pm (03/31/06) this started happening.
If anybody knows what this error means, or how to get rid of it (I really need to use this window in full-screen) then please let me know.