|
-
Aug 18th, 2005, 02:44 PM
#1
Thread Starter
Hyperactive Member
[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:
Dim sConnString As String
Dim rsTempRecordSet As New ADODB.Recordset
Dim cnTeamCMI As New ADODB.Connection
Dim sSQl As String
strConnString = "Driver= {MicrosoftAccessDriver(*.mdb)};DBQ=C:\Documents and Settings\ÅÓáÇã\ÓØÍ ÇáãßÊÈ\ÈÑäÇãÌ ÇáÍÖæÑ æ ÇáÇäÕÑÇÝ\database.mdb;Uid=Your_Username;Pwd=Your_Password;"
With cnTeamCMI
.ConnectionString = sConnString
.ConnectionTimeout = 0
.CursorLocation = adUseClient
.Open
End With
sSQl = "SELECT [ÑÕíÏ ÇáÅÌÇÒÇÊ] FROM [ÇáÅÏÇÑí] WHERE [ÇÓã ÇáÚÇãá] = '" & lstMngment.List(lstMngment.ListIndex) & "', ADOCn"
rsTempRecordSet.Open sSQl, cnTeamCMI, adOpenStatic, adLockReadOnly
With rsTempRecordSet
If .Fields("ÑÕíÏ ÇáÅÌÇÒÇÊ") = "9" Then
cmdMGTHoliday.Enabled = False
Else
cmdMGTHoliday.Enabled = True
End If
End With
rsTempRecordSet.Close
Set rsTempRecordSet = Nothing
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
-
Aug 18th, 2005, 02:48 PM
#2
Re: What's wrong with this code?
Try this:
VB Code:
With cnTeamCMI
.ConnectionString = sConnString
.ConnectionTimeout = 0
.CursorLocation = adUseClient
.Open strConnString '<==== You forgot to use your connection string
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."
-
Aug 18th, 2005, 02:50 PM
#3
Thread Starter
Hyperactive Member
Re: What's wrong with this code?
-
Aug 18th, 2005, 02:56 PM
#4
Re: What's wrong with this code?
 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:
strConnString = "Driver= {MicrosoftAccessDriver(*.mdb)};DBQ=C:\Documents and Settings\ÅÓáÇã\ÓØÍ ÇáãßÊÈ\ÈÑäÇãÌ ÇáÍÖæÑ æ ÇáÇäÕÑÇÝ\database.mdb;Uid=Your_Username;Pwd=Your_Password;"
Try this connection String:
VB Code:
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Documents and Settings\" & _
"ÅÓáÇã\ÓØÍ ÇáãßÊÈ\ÈÑäÇãÌ ÇáÍÖæÑ æ ÇáÇäÕÑÇÝ\database.mdb" & _
";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."
-
Aug 18th, 2005, 03:03 PM
#5
Thread Starter
Hyperactive Member
Re: What's wrong with this code?
Great, there are no errors now, but the code is not doing what I desire (if statement).
-
Aug 18th, 2005, 03:06 PM
#6
Thread Starter
Hyperactive Member
Re: What's wrong with this code?
OK, nevermind, it's al fixed and the code is functioning. Thanks so much man.
-
Aug 18th, 2005, 03:07 PM
#7
Re: What's wrong with this code?
 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."
-
Aug 18th, 2005, 03:08 PM
#8
Re: What's wrong with this code?
If the field is numeric, you don't need the quotes around the "9". Just use = 9
-
Aug 18th, 2005, 03:13 PM
#9
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:
If rsTempRecordSet.RecordCount > 0 Then
If .Fields("ÑÕíÏ ÇáÅÌÇÒÇÊ").Value = "9" Then
cmdMGTHoliday.Enabled = False
Else
cmdMGTHoliday.Enabled = True
End If
Else
'Do whatever you need to do if there are no records returned
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|