Solved

Run Time Error 3061

Posted on 2012-12-26
9
447 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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
 
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
Outlook Free & Paid Tools
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

776 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