Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    2 Star Lounger
    Join Date
    May 2002
    Location
    USA
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Error: Argument not Optional (MS Visual Studio-Enterprise)

    This is probably a simple problem but for some reason I am unable to figure it out.

    I have two text boxes and I don't want an error message to pop up when they click the OK button if the text in the boxes don't match. The text box that I need to make sure is the same as the first is bound to a database table as well. I thought I was doing this right, but then seeing as I'm only a week old at learning visual basic then it's a good possibility that I am doing it completely wrong. Here is my code. Please help.

    Private Sub cmdOK_Click()

    If txtPassword2 <> txtPassword1 Then
    MsgBox "Invalid Password Entered.", vbExclamation + vbOKOnly
    Set Focus = txtPassword1
    ElseIf txtPassword2 = txtPassword1 Then
    MoveToRecord

    End Sub

  2. #2
    2 Star Lounger
    Join Date
    May 2002
    Location
    USA
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error: Argument not Optional (MS Visual Studio-Enterprise)

    Ok I got the first error fixed, but I get the same error on the MoveToRecord part of my code. MoveToRecord is just the name of a subroutine, this should call it should it not? Here is my new code.

    Private Sub cmdOK_Click()

    If Forms!frmNewUser.txtPassword2.Value <> Forms!frmNewUser.txtPassword1.Value Then
    MsgBox "Invalid Password Entered.", vbExclamation + vbOKOnly
    Forms!frmNewUser.txtPassword1.SetFocus
    ElseIf Forms!frmNewUser.txtPassword2.Value = Forms!frmNewUser.txtPassword1.Value Then
    MoveToRecord

    End Sub

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Error: Argument not Optional (MS Visual Studio-Enterprise)

    Try using the Validate event of the second textbox to see if it matches the first one, that is, assuming the Validate event applies to bound textboxes, which I haven't tried. If Validate is available, it will keep the focus in that textbox if the validation fails and you can pop your error message up there. They can't click the OK button at all if the validate fails.

    In your code, you've left off the End If, which will give you one error message. Do you actually have a valid MoveToRecord routine? If you don't have any error handling in your code, an error in the MoveToRecord can be passed back up to the calling routine.
    Charlotte

  4. #4
    2 Star Lounger
    Join Date
    May 2002
    Location
    USA
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error: Argument not Optional (MS Visual Studio-Enterprise)

    I got most of it all figured out. I can do the validation either way. Except with the bound text box it is a little different. To validate it the way I'm doing it on the cmdOk_Click function I needed to add (0) at the end of the txtPassword2 to get the options I needed. I will look into doing it the other way. As for the MoveToRecord, I just forgot to call the case that I wanted so that was easy. It now reads
    MoveToRecord(adRsnAddNew)
    Thanks for your help.

  5. #5
    2 Star Lounger
    Join Date
    May 2002
    Location
    USA
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error: Argument not Optional (MS Visual Studio-Enterprise)

    Not to sure on how to use the validate function. Is it possible for you to post some sample code so I could work out how to use it for what I'm doing?

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Error: Argument not Optional (MS Visual Studio-Enterprise)

    It's not a function, it's a textbox event in VB6. Are you not seeing Validate listed in the available events for the textbox?
    Charlotte

  7. #7
    2 Star Lounger
    Join Date
    May 2002
    Location
    USA
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error: Argument not Optional (MS Visual Studio-Enterprise)

    Yes I am

  8. #8
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Error: Argument not Optional (MS Visual Studio-Enterprise)

    <hr>Yes I am <hr>
    Does that mean you DO see it? In that case, just put your code in there. The Validate event has a Cancel argument, so just set your Cancel to true if the textboxes don't match. That will keep the focus from leaving that textbox, and you can popup your message there to warn the user.
    Charlotte

  9. #9
    2 Star Lounger
    Join Date
    May 2002
    Location
    USA
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error: Argument not Optional (MS Visual Studio-Enterprise)

    OK. I actually just figured all the validation out, thanks for the help anway though. Now my only problem is that it is not writing to the database. Here is what I have for code now.

    Private Sub cmdOK_Click()

    If txtPassword2.Text = txtPassword1.Text Then
    MoveToRecord (adRsnAddNew)
    Else
    MsgBox "Invalid Password.", vbExclamation + vbOKOnly
    txtPassword1.SetFocus
    End If

    End Sub

    Private Sub Form_Load()

    Set m_recLogin = datLogin.Recordset

    End Sub

    Private Sub MoveToRecord(intDirection As Integer)

    On Error GoTo MoveToRecord_Err

    Select Case intDirection

    Case adRsnAddNew
    m_recLogin.AddNew
    m_recLogin("SOID") = txtAlias
    m_recLogin("Password") = txtPassword2

    End Select

    MoveToRecord_Exit:
    frmTotals.Show
    Exit Sub

    MoveToRecord_Err:
    Select Case Err.Number
    Case UPDATE_CANCELLED, ERRORS_OCCURRED
    'Do Nothing
    Case Else
    Err.Raise Err.Number, Err.Source, Err.Description
    End Select
    Resume MoveToRecord_Exit

    End Sub

    I think my problem lies in the part of my Case statement. I am not sure why it isn't writing to the database though.

  10. #10
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Error: Argument not Optional (MS Visual Studio-Enterprise)

    Are you sure adRsnAddNew is an integer? Most numeric arguments in VB/VBA are longs, although I don't know why it would make a difference in this case. You might try adding a m_recLogin.Update to see if that makes a difference. I don't use VB with bound data, so I can't say whether it's necessary or not. However, I've found it to be needed in Access ADO code in similar situations.
    Charlotte

  11. #11
    2 Star Lounger
    Join Date
    May 2002
    Location
    USA
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error: Argument not Optional (MS Visual Studio-Enterprise)

    I changed it to a long, string, whatever trying to get this thing to write to the database. I tried update, but it didn't seem to work. I'm not exactly sure why it won't save to the database, as far as I know it should work.

  12. #12
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Error: Argument not Optional (MS Visual Studio-Enterprise)

    Do you get an ADO error or just a zero records affected? Never mind, records affected is with an execute method, not an update method. The error question still stands though? And does your update method match your lock type?
    Charlotte

  13. #13
    2 Star Lounger
    Join Date
    May 2002
    Location
    USA
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error: Argument not Optional (MS Visual Studio-Enterprise)

    I get no error what so ever now. It runs through the code without a hitch. It just doesn't write it to the target table, or any other table. I've done some of my own research (as much as one can anyway) and I think in my adRsnAddNew Case I need to list the fields from the table there. Only thing is I've tried doing that a number of ways. I can't figure out how I'm supposed to do it. Thanks for any help provided.

  14. #14
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Error: Argument not Optional (MS Visual Studio-Enterprise)

    Are you using a DAO or an ADO recordset? Post the code you use to instantiate the recordset so that we're not just guessing on answers. If you used DAO, then the .Update method must be used to actually write the record. If you used ADO, then you have to trap ADO errors differently since they fail silently.
    Charlotte

  15. #15
    2 Star Lounger
    Join Date
    May 2002
    Location
    USA
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error: Argument not Optional (MS Visual Studio-Enterprise)

    I am using an ADO recordset. Here is my code for the ADO recordset.

    Private Sub Form_Load()

    Set m_recLogin = datLogin.Recordset

    End Sub

    Private Sub MoveToRecord(intDirection As Integer)

    On Error GoTo MoveToRecord_Err

    Select Case intDirection

    'Adds User name and Password to Database
    Case adRsnAddNew
    m_recLogin.AddNew

    End Select

    MoveToRecord_Exit:
    frmTotals.Show
    Exit Sub

    MoveToRecord_Err:
    Select Case Err.Number
    Case UPDATE_CANCELLED, ERRORS_OCCURRED
    'Do Nothing
    Case Else
    Err.Raise Err.Number, Err.Source, Err.Description
    End Select
    Resume MoveToRecord_Exit

    End Sub

Page 1 of 2 12 LastLast

Posting Permissions

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