Results 1 to 8 of 8
  1. #1
    christing is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2019
    Posts
    10

    i get error No value given for one or more required parameters on my program

    Private Sub getNextNumber()


    If Not app.State = ConnectionState.Open Then
    app.Open()
    End If
    'desc = sort/categories the data returned in descending order
    Dim da As New OleDb.OleDbDataAdapter("select top 1 ID from ADMIN order by ID desc;", app)
    Dim dt As New DataTable
    da.Fill(dt)
    app.Close()


    If dt.Rows.Count > 0 Then
    txtID.Text = (Val(dt.Rows(0)(0)) + 1).ToString.PadLeft(10, "A")
    Else
    txtID.Text = "1".PadLeft(10, "A")
    End If
    End Sub


    cmd.CommandText = "INSERT INTO ADMIN ([CusID],[Name]) " & _
    " VALUES(" & Me.txtID.Text & " , '" & Me.txtname.Text & "')"




    cmd.ExecuteNonQuery()


    MsgBox("Add Data Successful", MsgBoxStyle.OkOnly, "Message")


    cmd.CommandText = "UPDATE Admin" & _
    "SET" & _
    "[Name]='" & Me.txtname.Text & "'" & _
    "WHERE ID=" & Me.txtID.Tag
    MsgBox("Update Data Successful", MsgBoxStyle.OkOnly, "Message")




    cmd.ExecuteNonQuery()

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Why are you using Tag and Text properties?

    Need spaces in the SQL statement otherwise everything just runs together. Put them before the quote mark at end of each continued line:

    cmd.CommandText = "UPDATE Admin " & _
    "SET " & _
    "[Name]='" & Me.txtname & "' " & _
    "WHERE ID=" & Me.txtID

    Or just do one line:

    cmd.CommandText = "UPDATE Admin SET [Name]='" & Me.txtname & "' WHERE ID=" & Me.txtID

    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,205
    To expand on June's advice, the .Text property is used where you want to extract an entered value in n unbound control before it is saved.
    The Tag property has a different purpose and isn't appropriate here.
    Instead use the .Value property but as that's the default it can be omitted as June has done.
    Similarly for your INSERT code
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Colin, I have never had to use Text property, not even with unbound controls. Can use Text property only if control retains focus.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,205
    Its not something I do normally either and I understand why you mentioned about focus.
    However the following will show you what I mean
    Create a form with an unbound text box e.g. Text0 and a completely separate label Label2.
    Add the following code to the Text0_Change event: Me.Label2.Caption=Me.Text0.Text
    The caption will update as you type in the textbox.
    Now change the code to .Value instead of .Text (or just omit that part)
    As you type, you will get an invalid use of null error as nothing has been saved.
    Last edited by isladogs; 08-01-2019 at 01:32 PM.
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Understand, never had need for such a situation. Never used Change event. My point is that grabbing value input to UNBOUND control to use in code does not mandate Text property and may actually be inappropriate.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,205
    June
    Whilst you may never have used the Change event, many people do so in order to run e.g. search as you type procedures.
    Its a perfectly valid thing to do.

    These links may be useful https://docs.microsoft.com/en-us/off...s.textbox.text and https://stackoverflow.com/questions/...-in-vba-access

    To be honest, I don't understand what your point is.
    What does 'does not mandate Text property' mean and why 'may be inappropriate'.
    Perhaps you could explain what you think the purpose of the .Text property is.
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    I understand Text property has its use in that situation. My point is Text property is not mandatory for UNBOUND control in all situations which is what seemed to be implied by your earlier statement. Apologies if I misread what you tried to impart but in case someone else reads it same way, pointing out Value property also relevant for UNBOUND control. In the same vein, Text property does have functionality for BOUND control as well, but not as used by OP in this case.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 09-29-2015, 12:07 PM
  2. Report program required
    By proberts2014 in forum Forms
    Replies: 11
    Last Post: 07-02-2014, 02:15 PM
  3. Replies: 6
    Last Post: 10-30-2013, 05:17 PM
  4. Replies: 3
    Last Post: 07-23-2011, 08:34 AM
  5. Replies: 1
    Last Post: 09-09-2010, 04:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums