Results 1 to 9 of 9

Thread: [RESOLVED] What's wrong with this code?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Cairo, Egypt
    Posts
    275

    Resolved [RESOLVED] What's wrong with this code?

    Can someone please tell me what's wrong with this code. Been working on it for hours.
    VB Code:
    1. Dim sConnString As String
    2.     Dim rsTempRecordSet As New ADODB.Recordset
    3.     Dim cnTeamCMI As New ADODB.Connection
    4.     Dim sSQl As String
    5.     strConnString = "Driver= {MicrosoftAccessDriver(*.mdb)};DBQ=C:\Documents and Settings\ÅÓáÇã\ÓØÍ ÇáãßÊÈ\ÈÑäÇãÌ ÇáÍÖæÑ æ ÇáÇäÕÑÇÝ\database.mdb;Uid=Your_Username;Pwd=Your_Password;"
    6.     With cnTeamCMI
    7.         .ConnectionString = sConnString
    8.         .ConnectionTimeout = 0
    9.         .CursorLocation = adUseClient
    10.         .Open
    11.     End With
    12.         sSQl = "SELECT [ÑÕíÏ ÇáÅÌÇÒÇÊ] FROM [ÇáÅÏÇÑí] WHERE [ÇÓã ÇáÚÇãá] = '" & lstMngment.List(lstMngment.ListIndex) & "', ADOCn"
    13.         rsTempRecordSet.Open sSQl, cnTeamCMI, adOpenStatic, adLockReadOnly
    14. With rsTempRecordSet
    15.  
    16.     If .Fields("ÑÕíÏ ÇáÅÌÇÒÇÊ") = "9" Then
    17.         cmdMGTHoliday.Enabled = False
    18.     Else
    19.         cmdMGTHoliday.Enabled = True
    20.     End If
    21. End With
    22. rsTempRecordSet.Close
    23. Set rsTempRecordSet = Nothing
    24. Set cnTeamCMI = Nothing
    The error seems to be at the line ".open" where it tells me that it cannot find the record source (something like as I get the error message in Arabic).
    Any suggestions would be greatly appreciated. Thanx in advance

  2. #2
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: What's wrong with this code?

    Try this:


    VB Code:
    1. With cnTeamCMI
    2.         .ConnectionString = sConnString
    3.         .ConnectionTimeout = 0
    4.         .CursorLocation = adUseClient
    5.         .Open strConnString '<==== You forgot to use your connection string
    6.     End With


    Take a look at this Post on how to Connect to Access DB via ADO
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Cairo, Egypt
    Posts
    275

    Re: What's wrong with this code?

    Still same problem.

  4. #4
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: What's wrong with this code?

    Quote Originally Posted by ielashi
    Still same problem.
    I think I see your problem, it is in your Connection String you are not specifying which Access Driver:

    VB Code:
    1. strConnString = "Driver= {MicrosoftAccessDriver(*.mdb)};DBQ=C:\Documents and Settings\ÅÓáÇã\ÓØÍ ÇáãßÊÈ\ÈÑäÇãÌ ÇáÍÖæÑ æ ÇáÇäÕÑÇÝ\database.mdb;Uid=Your_Username;Pwd=Your_Password;"

    Try this connection String:

    VB Code:
    1. strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    2.                     "Data Source=C:\Documents and Settings\" & _
    3.                     "ÅÓáÇã\ÓØÍ ÇáãßÊÈ\ÈÑäÇãÌ ÇáÍÖæÑ æ ÇáÇäÕÑÇÝ\database.mdb" & _
    4.                      ";Jet OLEDB:Engine Type=5;"
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Cairo, Egypt
    Posts
    275

    Re: What's wrong with this code?

    Great, there are no errors now, but the code is not doing what I desire (if statement).

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Cairo, Egypt
    Posts
    275

    Re: What's wrong with this code?

    OK, nevermind, it's al fixed and the code is functioning. Thanks so much man.

  7. #7
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: What's wrong with this code?

    Quote Originally Posted by ielashi
    OK, nevermind, it's al fixed and the code is functioning. Thanks so much man.

    I glad I was able to help, don't forget to mark this thread as resolved.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: What's wrong with this code?

    If the field is numeric, you don't need the quotes around the "9". Just use = 9

  9. #9
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: [RESOLVED] What's wrong with this code?

    I was looking at you code again and you should probably check to make sure that your query returned any records:


    VB Code:
    1. If rsTempRecordSet.RecordCount > 0 Then
    2.     If .Fields("ÑÕíÏ ÇáÅÌÇÒÇÊ").Value = "9" Then
    3.         cmdMGTHoliday.Enabled = False
    4.     Else
    5.         cmdMGTHoliday.Enabled = True
    6.     End If
    7. Else
    8.        'Do whatever you need to do if there are no records returned
    9. End If
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width