Solved

Run Time Error 3061

Posted on 2012-12-26
9
443 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>>> 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This collection of functions covers all the normal rounding methods of just about any numeric value.
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
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 …

762 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

10 Experts available now in Live!

Get 1:1 Help Now