Results 1 to 7 of 7

Thread: [RESOLVED] Error : ByRef argument type mismatch

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Posts
    688

    Resolved [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

  2. #2
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Error : ByRef argument type mismatch

    Is strDB declared as a string?

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Posts
    688

    Re: Error : ByRef argument type mismatch

    Hi

    Yes i have declared string variable

    Thanks

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    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

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    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

  6. #6
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    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.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Posts
    688

    Re: Error : ByRef argument type mismatch

    Thks Miser

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