Solved

Run Time Error 3061

Posted on 2012-12-26
9
445 Views
Last Modified: 2012-12-30
See the attached file
Run-time-error3061.docx
0
Comment
Question by:laylaAF
  • 4
  • 3
  • 2
9 Comments
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 250 total points
ID: 38721110
If your status field is text, you need to embed it in quotes.

>>> Set rs = myDB.OpenRecordset("SELECT * FROM Status WHERE Code = " & StatusC)

Try changing this line to:

Set rs = myDB.OpenRecordset("SELECT * FROM Status WHERE Code = '" & StatusC & "'")

Open in new window

0
 
LVL 29

Assisted Solution

by:IrogSinta
IrogSinta earned 250 total points
ID: 38721129
In addition to what Miriam said, you should create a query that joins your 4 tables.  That way you only need to open a single recordset based on the query rather than opening 4 separate recordsets as you have it.
0
 

Author Comment

by:laylaAF
ID: 38729128
Thakn you mbizup. It works I do not receive the error any more. But dose nto post the result in the combo box.

IrogSinta. What is the different to make it in one Query. I am afraid to be more complicated.

Thank you.
0
 
LVL 61

Accepted Solution

by:
mbizup earned 250 total points
ID: 38729154
>>> But dose nto post the result in the combo box.

That may prove very difficult to resolve without actually seeing a sample database illustrating that issue.  There are many possible reasons for this...

- There are no records matching the criteria you are using to look up the value you are trying to place in the combo -- so result of your lookup is null.

-  The combo name might me incorrect (double-check that the combo is really named comboStatus).

- There are a variety of design properties that might prevent your combo from displaying data in some situations.


Also, as an aside, this entire block of code:

'-------------------------------------------
'List data in the Status field

Set rs = myDB.OpenRecordset("SELECT * FROM Status WHERE Code = " & StatusC)

ComboStatus = rs!Status


'Close and reset the connection
rs.Close
Set rs = Nothing

Open in new window


Can be replaced with a single line:

ComboStatus = DLookup("Status", "Status", "Code = '" & StatusC & "'")

Open in new window

0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 250 total points
ID: 38729160
Just to help track down the problem, try adding a couple of message boxes to your code to display values as the code is executing:

Msgbox " We are looking up the status for the following code: " &  StatusC
Msgbox "This is the status for that code: " & DLookup("Status", "Status", "Code = '" & StatusC & "'")

Open in new window


Are the values displayed by the message boxes what you are expecting to see?
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38729166
One more note - I realize it is not always possible to respond immediately, but it makes it a lot easier for us to help you resolve your problems if you respond in a timely manner (ideally within the same day).  When your feedback is delayed for days at a time, it is easy to lose track of what the issue is and where we left off.
0
 
LVL 29

Assisted Solution

by:IrogSinta
IrogSinta earned 250 total points
ID: 38729268
What is the different to make it in one Query. I am afraid to be more complicated.
On the contrary, if you add all 4 tables to a query in Design View, then drag the 10 fields you use for the textboxes down to the Field section, then save your query with the name qryTransactions, your code will be shortened to this:
Private Sub ComboSearchT_AfterUpdate()
    Dim myDB As Database
    Dim rs As DAO.Recordset
    
    ' Activite the button
    Me!ComUpdateR.Enabled = True
    Me!ComDelete.Enabled = True
    
    'Open Connection
    Set myDB = CurrentDb()
    Set rs = myDB.OpenRecordset("SELECT * FROM qryTransaction WHERE ID = " & ComboSearchT)
    
    'List data in the fields
    TextTransaction = rs!Transaction
    TextSAC = rs!SignatoryAuthorityCorporate
    TextSAR = rs!SignatoryAuthorityRiyadh
    TextSAJ = rs!SignatoryAuthorityJeddah
    TextRef = rs!Reference
    TextED = rs!EffectDate
    TextNVD = rs!NotValidDate
    TextCategory = rs!Category
    TextType = rs!Type
    
    ComboStatus = rs!Status
    
    'Close and reset the connection
    rs.Close
    Set rs = Nothing

End Sub

Open in new window

0
 
LVL 29

Assisted Solution

by:IrogSinta
IrogSinta earned 250 total points
ID: 38729277
If your form is unbound, another possibility is to set your form's recordsource to the query and then bind the textboxes to these fields.  You then can add a criteria to the query's ID field to point to Forms!NameOfYourForm!ComboSearchT.  Then you code will be shortened to this:
Private Sub ComboSearchT_AfterUpdate()    
    ' Activite the button
    Me!ComUpdateR.Enabled = True
    Me!ComDelete.Enabled = True

    Me.Requery

End Sub

Open in new window

0
 

Author Closing Comment

by:laylaAF
ID: 38730640
Thank you very much for your help. I have changed the code to the following code and change the properties of the ComboStatus. It is working now.

Private Sub ComboSearchT_AfterUpdate()

Dim TypeID As Integer

'Declare the Connection
Dim myDB As Database
Dim rs As DAO.Recordset

'Open Connection
Set myDB = CurrentDb()
Set rs = myDB.OpenRecordset("SELECT * FROM Transaction WHERE ID = " & ComboSearchT)


' Activite the button
Me!ComUpdateR.Enabled = True
Me!ComDelete.Enabled = True

'List data in the fields
TextTransaction = rs!Transaction
TextSAC = rs!SignatoryAuthorityCorporate
TextSAR = rs!SignatoryAuthorityRiyadh
TextSAJ = rs!SignatoryAuthorityJeddah
TextRef = rs!Reference
TextED = rs!EffectDate
TextNVD = rs!NotValidDate

TextCategory = DLookup("Category", "Category", "ID = " & rs!IDCategory)
TypeID = DLookup("IDType", "Category", "ID = " & rs!IDCategory)
TextType = DLookup("Type", "Type", "ID = " & TypeID)
ComboStatus = DLookup("Status", "Status", "Code = '" & rs!Status & "'")

'Close and reset the connection
rs.Close
Set rs = Nothing

End Sub
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now