Results 1 to 9 of 9
  1. #1
    smikkelsen is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Mar 2010
    Posts
    60

    New record button

    I would like to add a button that when clicked will add a new record with specific text.

    For example, when the button is clicked it will atomatically add the text "auto note" + whatever is in a field on the form.



    Say I have a field named "note" and it is not stored in a table, it is just for inputting text. Then once the text is typed, you would click the add button and it would automatically add a new record with text: "<Auto Note>" & [note]

    I hope this makes sense. I have tried a bunch of things, but I don't know what I'm doing to be honest. I have never tried this before.

  2. #2
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Here is What I have done
    I table: exp

    ID = Auto Number PK
    Type_text= Text

    In the Form in the Text box type a Text the same is entered in the exp table with a autonote Maximus:
    e.g. If you type Gorge, "Maximus George" will be entered in the table check it out.

    Code on the Button:


    Private Sub Command2_Click()
    On Error GoTo Err_Command2_Click
    Dim strConString As String
    Dim strSQL As String

    If isull(Me.Text0) Then
    MsgBox "Please Type a Text", vbInformation, "No Text"
    Else
    strConString = "Maximus" & " " & Me.Text0 'Attaching Auto Text to the typed string
    strSQL = "Insert Into exp(Type_text) Values(" & "'" & strConString & "');" 'Using SQL to enter data in the Table
    DoCmd.SetWarnings False
    DoCmd.RunSQL strSQL
    DoCmd.SetWarnings True
    DoCmd.Requery "List3" 'List Box Displaying The results
    End If
    Exit_Command2_Click:
    Exit Sub

    Err_Command2_Click:
    MsgBox Err.Description
    Resume Exit_Command2_Click

    End Sub


    if this solves your problem mark the thread solved.

  3. #3
    smikkelsen is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Mar 2010
    Posts
    60
    Thanks for the reply. I tried that, and I think it is what I am trying to do, but there is one problem. The field I am trying to put the text in, is a new record.

    Let me explain. I have form [Main_tracking_notes] with continuous records. I have this text field (that I will type into) and the button in the header of the form. When clicked, I need it to add the auto note, and text to a new record. I'm sorry I didn't explain that before, I thought it would be the same process.

    Thanks again for your help. If you know what I need to change to make that work, let me know.

    Thanks!

  4. #4
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    This is what I have done:

    1) Continous form.
    2) Text Box and The Button at the Form Header
    3) Type the Text and Click Button Text with the Auto Note entered in the form as Entry.

    if this solves your problem mark this thread solved.

  5. #5
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    is you problem solved

  6. #6
    smikkelsen is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Mar 2010
    Posts
    60
    I'm sorry I hadn't had a chance to try it yet, I finally went to bed at 5 am.



    Ok, after changing the few things that you sent, it works great! Thanks you!

    I am sorry to ask, but I am trying now to add a second field in that vb code to update with the username, and would also like to add a third field as well. I'm a newbie at VB so I am doing something wrong, thanks for your patients.

    Here is what I have:

    Code:
     
    Private Sub Command19_Click()
    On Error GoTo Err_Command19_Click
    Dim strConString As String
    Dim strSQL As String
    Dim strSQL2 As String
    If IsNull(Me.Text0) Then
    MsgBox "Enter Note First!", vbInformation, "No Text"
    Else
    strConString = "<Auto Note>  " & " " & Me.Text0
    strConString2 = fOSUserName()
    strSQL = "Insert Into Main_Tracking_Notes(comment) Values(" & "'" & strConString & "'); Insert Into Main_Tracking_Notes(user) Values(" & "'" & strConString2 & "');"
     
    DoCmd.SetWarnings False
    DoCmd.RunSQL strSQL
    DoCmd.SetWarnings True
     
    Me.Requery
    End If
     
    Exit_Command19_Click:
        Exit Sub
    Err_Command19_Click:
        MsgBox Err.Description
        Resume Exit_Command19_Click
     
    End Sub
    So I tried to add another thing to the strSQL line, but I think that is wrong. I'm not sure where to put it.

  7. #7
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Below is the code that you had modified:

    strSQL = "Insert Into Main_Tracking_Notes(comment) Values(" & "'" & strConString & "'); Insert Into Main_Tracking_Notes(user) Values(" & "'" & strConString2 & "');"

    This will be the correct Code:

    strSQL = "Insert Into Main_Tracking_Notes(comment,user) Values(" & "'" & strConString & "'," & "'" & strConstring2 & "');"

    Please follow this syntax while putting in more field names.


    if this solves your problem mark the thread solved.

  8. #8
    smikkelsen is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Mar 2010
    Posts
    60
    Worked perfectly! Thanks so much for your help and time.

  9. #9
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Glad to help.

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

Similar Threads

  1. Add new record button
    By smikkelsen in forum Access
    Replies: 0
    Last Post: 03-29-2010, 02:55 PM
  2. Replies: 6
    Last Post: 02-09-2010, 07:53 AM
  3. Command button help - delete record
    By Zukster in forum Forms
    Replies: 0
    Last Post: 08-27-2009, 08:47 AM
  4. make Add Record button work
    By janjan_376 in forum Forms
    Replies: 3
    Last Post: 06-05-2009, 04:22 AM
  5. Find Record button error
    By Zedlexx in forum Forms
    Replies: 0
    Last Post: 03-11-2009, 09:26 AM

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