Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2003
    Posts
    15

    Question Unanswered: Unbound Controles - Save Record - Help

    Hi

    My question is,

    How can I save information held in unbound controls, such as text boxes and so on, which are located on the form, to a new record in a table. Now the reason why I have chosen not to bind the controls is to stop people looking at other bookings.
    So what I wanted is to completely detach the form from the table, and use a "Save Record" button to do the job.

    Again I really would appreciate Help on this.

    Thanks

    Chris

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    one way is to open a recordset on the table:

    private sub buttonSaveRecord_Click()
    dim dabs as dao.database
    dim recs as dao.recordset
    set dabs=currentdb
    set recs=dabs.openrecordset("theNameOfYourTable")
    recs.addnew
    recs!thisField=thisTextBox.value
    recs!thatField=thatTextBox.value
    recs.update
    set recs=nothing
    set dabs=nothing
    end sub

    ...replacing the stuff in italics with the real names of course.

    (above is DAO code, you need the same idea but a different recordset syntax in ADO)

    izy
    currently using SS 2008R2

  3. #3
    Join Date
    Dec 2003
    Posts
    15
    Thanks izy, I'll give this a try and tell you how it went.

    Chris

  4. #4
    Join Date
    Dec 2003
    Location
    Belfast, UK
    Posts
    87

    Question for izyrider

    Hi izy,

    You seem to be one of the main people for this type of thing, is it possible to do the reverse and open a record on an unbound form?

    Thanks!

    Originally posted by izyrider
    one way is to open a recordset on the table:

    private sub buttonSaveRecord_Click()
    dim dabs as dao.database
    dim recs as dao.recordset
    set dabs=currentdb
    set recs=dabs.openrecordset("theNameOfYourTable")
    recs.addnew
    recs!thisField=thisTextBox.value
    recs!thatField=thatTextBox.value
    recs.update
    set recs=nothing
    set dabs=nothing
    end sub

    ...replacing the stuff in italics with the real names of course.

    (above is DAO code, you need the same idea but a different recordset syntax in ADO)

    izy

  5. #5
    Join Date
    Dec 2003
    Posts
    268

    Yep

    You can create a recordset store the values for that record set then pass those values to thier respective text box.

    dim db as dao.recordset
    dim rs as recordset
    dim ctl as control

    set db= currentdb
    set rs = db.openrecordset("SELECT fname, lname, ID FROM Employee WHERE ID = 1")

    rs.movefirst
    for i = 0 to rs.recordcount
    ctl = ctl.name("txt" & rs.field.name)
    ctl.text = rs.field(i)
    next i
    set rs = nothing
    set db = nothing

    this should work for any record set where you only return one record. This also makes the assumption that the control's name is = to the respective column name in the query. i.e. txtfname would be for the first column.

    This is just an example you will have to substitute in your applicable information

  6. #6
    Join Date
    Dec 2003
    Location
    Belfast, UK
    Posts
    87

    Thanks

    Thanks i'll give it a go.

Posting Permissions

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