|
-
Apr 9th, 2013, 03:50 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Error : ByRef argument type mismatch
Hi
Ob this line
If IsDatabaseAvailable(strDB)
it is giving me this error " ByRef argument type mismatch"
strDB = "Jaggan" ' Database Name
If IsDatabaseAvailable(strDB) Then
cnn1.Open "Driver=SQL Server;Server=" & ServerName & ";Database=" & strDatabase & ";uid=" & uid & ";pwd=" & pwd & ";"
Endif
Private Function IsDatabaseAvailable(strDatabase As String) As Boolean
Dim conFind As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL, m_database As String
Set conFind = New ADODB.Connection
Set rs = New ADODB.Recordset
conFind.ConnectionString = "Provider = sqloledb;Data Source=" & ServerName & ";uid=" & uid & ";pwd=" & pwd
conFind.Open
m_database = "Test"
strSQL = "SELECT Name FROM master..sysdatabases WHERE Name = '" & m_database & "'"
rs.Open strSQL, conFind, adOpenStatic, adLockOptimistic
If Not (rs.EOF And rs.BOF) Then
IsDatabaseAvailable = True
End If
rs.Close
Set rs = Nothing
conFind.Close
Set conFind = Nothing
End Function
Thanks
-
Apr 9th, 2013, 06:35 AM
#2
Re: Error : ByRef argument type mismatch
Is strDB declared as a string?
-
Apr 9th, 2013, 11:49 PM
#3
Thread Starter
Fanatic Member
Re: Error : ByRef argument type mismatch
Hi
Yes i have declared string variable
Thanks
-
Apr 9th, 2013, 11:57 PM
#4
Re: Error : ByRef argument type mismatch
Is it declared in scope where the error occurs?
Code:
Private Sub MySub()
Dim strDB as String
strDB = "Jaggan" ' Database Name
If IsDatabaseAvailable(strDB) Then
' more code
End Sub
Would be fine
Code:
Private Sub Form_Load()
Dim strDB as String
'more code
End Sub
Private Sub MySub()
strDB = "Jaggan" ' Database Name
If IsDatabaseAvailable(strDB) Then
' more code
End Sub
Would generate an error
-
Apr 9th, 2013, 11:59 PM
#5
Re: Error : ByRef argument type mismatch
note
Code:
Dim strSQL, m_database As String
In the code above strSql is not declared as a string so if you did it like this even if it is in scope then it still is not right what that codes tells VB is
Code:
Dim strSQL as Variant, m_database As String
If you want it to be a string you have to tell it so
-
Apr 10th, 2013, 12:05 AM
#6
Re: Error : ByRef argument type mismatch
You have not shown us all the code prior to making the call
What may be causing your problem is using declarations similar to this -
Dim strSQL, m_database As String
Instead use -
Dim strSQL as String, m_database As String
You must specifically mention the data type for each variable on a combined line.
-
Apr 10th, 2013, 01:16 AM
#7
Thread Starter
Fanatic Member
Re: Error : ByRef argument type mismatch
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
|