?
Solved

Run Time Error 3061

Posted on 2012-12-26
9
Medium Priority
?
452 Views
Last Modified: 2012-12-30
See the attached file
Run-time-error3061.docx
0
Comment
Question by:laylaAF
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 1000 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 1000 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
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
LVL 61

Accepted Solution

by:
mbizup earned 1000 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
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 1000 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 1000 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 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
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 …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

752 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