[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 :)
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
Re: What's wrong with this code?
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:
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;"
Re: What's wrong with this code?
Great, there are no errors now, but the code is not doing what I desire (if statement).
Re: What's wrong with this code?
OK, nevermind, it's al fixed and the code is functioning. Thanks so much man.
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. :wave:
Re: What's wrong with this code?
If the field is numeric, you don't need the quotes around the "9". Just use = 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