Solved

Run Time Error 3061

Posted on 2012-12-26
9
449 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 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
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!

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

696 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