Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2003
    Posts
    30

    Unanswered: 2 Error Messages Same Line

    Hi, All!

    I get 2 different error messages, depending on the use of quotation marks, with the same line of code. If I do (From_transfr) I get "ByRef argument type mismatch." If I use the quotes, I get "Type mismatch".

    Private Sub cmdsave_rec_Click()
    Dim From_tranfr As Integer
    Dim To_tranfr As Integer
    Dim Amt As Currency

    If IsNull(Me!cmbFrom) Or IsNull(Me!cmbTo) Or IsNull(Me!txtAmount) Or Me!txtAmount <= 0 Then
    MsgBox "All data is required, Please enter information!", vbCritical + vbOKOnly, Application.Name
    Exit Sub
    End If

    From_tranfr = CInt(Me!cmbFrom)
    To_tranfr = CInt(Me!cmbTo)
    Amt = Me!txtAmount

    'This is the "offending" line:
    If MsgBox("Move amount to? " & Format(Amt, "$#,##0.00") & " from account '" & findAcct_Name("From_transfr") & _
    "' to account '" & findAcct_Name("To_tranfr") & "'" & Chr(10) & "Is this correct?", vbQuestion + vbYesNo, Application.Name) = vbYes Then

    Can somebody just point me in the right direction. If I don't figure it out "myself", I won't learn anything.

    If you need moe information, please let me know.

    Thanks in advance,

    Bob

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    How are you defining the function findAcct_Name? Does it return a value? What parameter(s) are you passing and by what method?

  3. #3
    Join Date
    Sep 2003
    Posts
    30
    Originally posted by M Owen
    How are you defining the function findAcct_Name? Does it return a value? What parameter(s) are you passing and by what method?
    . . . defining the function . . .
    Function findAcct_Name(acct As Integer) As String
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset

    rs.Open "Select Acct_Descript from tblacct_type where Acct_Id =" & acct, CurrentProject.Connection, adOpenStatic, adLockOptimistic

    If rs.RecordCount > 0 Then
    findAcct_Name = rs!Acct_Descript
    End If

    rs.Close
    Set rs = Nothing
    End Function

    Dim From_tranfr As Integer
    Dim To_tranfr As Integer

    Does it return a value?
    If MsgBox("Move amount to? " & Format(Amt, "$#,##0.00") & " from account '" & findAcct_Name("From_transfr") & _
    "' to account '" & findAcct_Name("To_tranfr") & "'" & Chr(10) & "Is this correct?", vbQuestion + vbYesNo, Application.Name) = vbYes Then

    Message box says:
    Move amount to? $20.00 from account Checking (From_transfr) to Savings (To_Transfr). Is this correct?

    . . .by what method?

    ByRef - is what I believe you mean.

    What parameter(s) are you passing . . .
    From_tranfr = CInt(Me!cmbFrom)
    To_tranfr = CInt(Me!cmbTo)

    I hope this is what you were asking, if not, please don't hesitate . . .

    Thanks in advance,

    Bob

  4. #4
    Join Date
    Sep 2003
    Posts
    30
    Originally posted by M Owen
    How are you defining the function findAcct_Name? Does it return a value? What parameter(s) are you passing and by what method?
    . . . defining the function . . .
    Function findAcct_Name(acct As Integer) As String
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset

    rs.Open "Select Acct_Descript from tblacct_type where Acct_Id =" & acct, CurrentProject.Connection, adOpenStatic, adLockOptimistic

    If rs.RecordCount > 0 Then
    findAcct_Name = rs!Acct_Descript
    End If

    rs.Close
    Set rs = Nothing
    End Function

    Dim From_tranfr As Integer
    Dim To_tranfr As Integer

    Does it return a value?
    If MsgBox("Move amount to? " & Format(Amt, "$#,##0.00") & " from account '" & findAcct_Name("From_transfr") & _
    "' to account '" & findAcct_Name("To_tranfr") & "'" & Chr(10) & "Is this correct?", vbQuestion + vbYesNo, Application.Name) = vbYes Then

    Message box says:
    Move amount to? $20.00 from account Checking (From_transfr) to Savings (To_Transfr). Is this correct?

    . . .by what method?

    ByRef - is what I believe you mean.

    What parameter(s) are you passing . . .
    From_tranfr = CInt(Me!cmbFrom)
    To_tranfr = CInt(Me!cmbTo)

    I hope this is what you were asking, if not, please don't hesitate . . .

    Thanks in advance,

    Bob

  5. #5
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Bob,

    Couple of things ... Your parameter is ByRef (default - not explicit). No Problem ...

    Problem(s):

    1) Return value. I don't see a default return value ... What if there is no matching account?

    2) ADODB recordsets. When you use this kind of recordset, you are not automatically on the 1st record. You must perform a MoveFirst call ... Also, you are by default using serverside cursor so your RecordCount test will fail ... It's value is -1 = indeterminant. Set the CursorType to adUseClient ...

    3) Passing values. Pass in the field name not in quotations ...

  6. #6
    Join Date
    Sep 2003
    Posts
    30
    Originally posted by M Owen
    Bob,

    Couple of things ... Your parameter is ByRef (default - not explicit). No Problem ...

    Problem(s):

    1) Return value. I don't see a default return value ... What if there is no matching account?

    2) ADODB recordsets. When you use this kind of recordset, you are not automatically on the 1st record. You must perform a MoveFirst call ... Also, you are by default using serverside cursor so your RecordCount test will fail ... It's value is -1 = indeterminant. Set the CursorType to adUseClient ...

    3) Passing values. Pass in the field name not in quotations ...
    . . . no matching account? There are only 2 options: Checking(2) or Savings(1)

    When I used Option Explicit, I found the errors, which were the typical spelling ones. One place I had From_transfr and another place I had From_tranfr.

    I've got 3 out of 4 forms working. (2 of the 4 forms weren't giving me problems.) I'm now working on the last one.

    I'm having problems with a row source (sql) that I created with the query builder, but I'll see what I can do before asking for help.

    Thanks for your help!

    Later,

    Bob

    PS

    I will be making the change with the cursor as you suggested. I will also check the code for the MoveFirst

Posting Permissions

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