A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Can I modify A Text Box under program control?



 
 
Thread Tools Display Modes
  #11  
Old August 28th, 2007, 04:34 PM posted to microsoft.public.access.gettingstarted
Ray C
external usenet poster
 
Posts: 215
Default Can I modify A Text Box under program control?

Thanks John I will give it a try. Cureous about the "Dirty" bit though.

I realy appreciate your help. RayC

"John Spencer" wrote:

Add a button to your form "New Record"

In the click event add code to go to NEW Record.

THe code you need to add for the buttons click event should look
something like

On Error GoTo Err_sCmdAdd

With Me
If .Dirty = True Then .Dirty = False

If .AllowAdditions = False Then
.AllowAdditions = True
End If

DoCmd.GoToRecord , , acNewRec

End With

Exit_sCmdAdd:
Exit Function

Err_sCmdAdd:
MsgBox Err.Number & ": " & Err.Description,



'================================================= ===
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'================================================= ===


Ray C wrote:
It's only confusing because You know what I should be diong and I don't know
what I am doing :-)
I have a Form and I have Text Boxes on thst Form that are "Bound" to fields
in a Table. This is great if all I want to do is look at the information in
that Table but I might want to add a new record at some time and it is this
that I am working my way through. I don't have navigation Buttons on my Form
so I am not able to go to the last record and enter new information then
save. Could I do that under program control?
Hope this helps RayC

"scubadiver" wrote:

What are you trying to do? Sounds very confused to me.


--
The 11th day of every month:

http://truthaction.org/forum/index.php


"Ray C" wrote:

I have a number of "Bound" Text Boxes that display the appropriate records in
a Table (e.g. Mame, Address, etc) but I will want to add new records at some
time and I also Duplicate those same Text Boxes and have them "Unbound" so
that I can enter new info into them. I then I write that data to a new record
by using the following :- where ****TxtBox is the "Unbound" Text Box.

Private Sub SaveRecord()

Dim db As Database, rs1 As Recordset

Set db = CurrentDb
Set rs1 = db.OpenRecordset("tbl_Customer", dbOpenDynaset)
rs1.MoveLast
With rs1
.AddNew ' Add new record to end of Recordset
Object.
![Name] = NameTxtBox
![Addr1] = Addr1TxtBox
![Addr2] = Addr2TxtBox
Etc, Etc
.Update
End With
rs1.Close: db.Close

End Sub

If I could change the Text Box under Program control, it would save
duplicating all those extra boxes.

Or is there a better way to do it?

Thanks RayC


  #12  
Old August 28th, 2007, 05:19 PM posted to microsoft.public.access.gettingstarted
John Spencer
external usenet poster
 
Posts: 2,364
Default Can I modify A Text Box under program control?

The dirty bit forces a save of the current record if it has not yet been
saved.

'================================================= ===
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'================================================= ===


Ray C wrote:
Thanks John I will give it a try. Cureous about the "Dirty" bit though.

I realy appreciate your help. RayC

"John Spencer" wrote:

Add a button to your form "New Record"

In the click event add code to go to NEW Record.

THe code you need to add for the buttons click event should look
something like

On Error GoTo Err_sCmdAdd

With Me
If .Dirty = True Then .Dirty = False

If .AllowAdditions = False Then
.AllowAdditions = True
End If

DoCmd.GoToRecord , , acNewRec

End With

Exit_sCmdAdd:
Exit Function

Err_sCmdAdd:
MsgBox Err.Number & ": " & Err.Description,



'================================================= ===
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'================================================= ===


Ray C wrote:
It's only confusing because You know what I should be diong and I don't know
what I am doing :-)
I have a Form and I have Text Boxes on thst Form that are "Bound" to fields
in a Table. This is great if all I want to do is look at the information in
that Table but I might want to add a new record at some time and it is this
that I am working my way through. I don't have navigation Buttons on my Form
so I am not able to go to the last record and enter new information then
save. Could I do that under program control?
Hope this helps RayC

"scubadiver" wrote:

What are you trying to do? Sounds very confused to me.


--
The 11th day of every month:

http://truthaction.org/forum/index.php


"Ray C" wrote:

I have a number of "Bound" Text Boxes that display the appropriate records in
a Table (e.g. Mame, Address, etc) but I will want to add new records at some
time and I also Duplicate those same Text Boxes and have them "Unbound" so
that I can enter new info into them. I then I write that data to a new record
by using the following :- where ****TxtBox is the "Unbound" Text Box.

Private Sub SaveRecord()

Dim db As Database, rs1 As Recordset

Set db = CurrentDb
Set rs1 = db.OpenRecordset("tbl_Customer", dbOpenDynaset)
rs1.MoveLast
With rs1
.AddNew ' Add new record to end of Recordset
Object.
![Name] = NameTxtBox
![Addr1] = Addr1TxtBox
![Addr2] = Addr2TxtBox
Etc, Etc
.Update
End With
rs1.Close: db.Close

End Sub

If I could change the Text Box under Program control, it would save
duplicating all those extra boxes.

Or is there a better way to do it?

Thanks RayC

  #13  
Old August 28th, 2007, 06:52 PM posted to microsoft.public.access.gettingstarted
Ray C
external usenet poster
 
Posts: 215
Default Can I modify A Text Box under program control?

Ahh, interesting, I will try to remember that.
With regard to your excelent solution to my problem, do I need to have
something that will save the record or will it save automatically. Also,
should I not be putting something in there that asks the user if they want to
save or not?

Regards RayC

"John Spencer" wrote:

The dirty bit forces a save of the current record if it has not yet been
saved.

'================================================= ===
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'================================================= ===


Ray C wrote:
Thanks John I will give it a try. Cureous about the "Dirty" bit though.

I realy appreciate your help. RayC

"John Spencer" wrote:

Add a button to your form "New Record"

In the click event add code to go to NEW Record.

THe code you need to add for the buttons click event should look
something like

On Error GoTo Err_sCmdAdd

With Me
If .Dirty = True Then .Dirty = False

If .AllowAdditions = False Then
.AllowAdditions = True
End If

DoCmd.GoToRecord , , acNewRec

End With

Exit_sCmdAdd:
Exit Function

Err_sCmdAdd:
MsgBox Err.Number & ": " & Err.Description,



'================================================= ===
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'================================================= ===


Ray C wrote:
It's only confusing because You know what I should be diong and I don't know
what I am doing :-)
I have a Form and I have Text Boxes on thst Form that are "Bound" to fields
in a Table. This is great if all I want to do is look at the information in
that Table but I might want to add a new record at some time and it is this
that I am working my way through. I don't have navigation Buttons on my Form
so I am not able to go to the last record and enter new information then
save. Could I do that under program control?
Hope this helps RayC

"scubadiver" wrote:

What are you trying to do? Sounds very confused to me.


--
The 11th day of every month:

http://truthaction.org/forum/index.php


"Ray C" wrote:

I have a number of "Bound" Text Boxes that display the appropriate records in
a Table (e.g. Mame, Address, etc) but I will want to add new records at some
time and I also Duplicate those same Text Boxes and have them "Unbound" so
that I can enter new info into them. I then I write that data to a new record
by using the following :- where ****TxtBox is the "Unbound" Text Box.

Private Sub SaveRecord()

Dim db As Database, rs1 As Recordset

Set db = CurrentDb
Set rs1 = db.OpenRecordset("tbl_Customer", dbOpenDynaset)
rs1.MoveLast
With rs1
.AddNew ' Add new record to end of Recordset
Object.
![Name] = NameTxtBox
![Addr1] = Addr1TxtBox
![Addr2] = Addr2TxtBox
Etc, Etc
.Update
End With
rs1.Close: db.Close

End Sub

If I could change the Text Box under Program control, it would save
duplicating all those extra boxes.

Or is there a better way to do it?

Thanks RayC


  #14  
Old August 29th, 2007, 12:29 AM posted to microsoft.public.access.gettingstarted
John Spencer
external usenet poster
 
Posts: 2,364
Default Can I modify A Text Box under program control?

Actually, it should save automatically. Access does that. I can't
remember why I put that bit in there - probably paranoia on my part.

'================================================= ===
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'================================================= ===


Ray C wrote:
Ahh, interesting, I will try to remember that.
With regard to your excelent solution to my problem, do I need to have
something that will save the record or will it save automatically. Also,
should I not be putting something in there that asks the user if they want to
save or not?

Regards RayC

"John Spencer" wrote:

The dirty bit forces a save of the current record if it has not yet been
saved.

'================================================= ===
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'================================================= ===


Ray C wrote:
Thanks John I will give it a try. Cureous about the "Dirty" bit though.

I realy appreciate your help. RayC

"John Spencer" wrote:

Add a button to your form "New Record"

In the click event add code to go to NEW Record.

THe code you need to add for the buttons click event should look
something like

On Error GoTo Err_sCmdAdd

With Me
If .Dirty = True Then .Dirty = False

If .AllowAdditions = False Then
.AllowAdditions = True
End If

DoCmd.GoToRecord , , acNewRec

End With

Exit_sCmdAdd:
Exit Function

Err_sCmdAdd:
MsgBox Err.Number & ": " & Err.Description,



'================================================= ===
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'================================================= ===


Ray C wrote:
It's only confusing because You know what I should be diong and I don't know
what I am doing :-)
I have a Form and I have Text Boxes on thst Form that are "Bound" to fields
in a Table. This is great if all I want to do is look at the information in
that Table but I might want to add a new record at some time and it is this
that I am working my way through. I don't have navigation Buttons on my Form
so I am not able to go to the last record and enter new information then
save. Could I do that under program control?
Hope this helps RayC

"scubadiver" wrote:

What are you trying to do? Sounds very confused to me.


--
The 11th day of every month:

http://truthaction.org/forum/index.php


"Ray C" wrote:

I have a number of "Bound" Text Boxes that display the appropriate records in
a Table (e.g. Mame, Address, etc) but I will want to add new records at some
time and I also Duplicate those same Text Boxes and have them "Unbound" so
that I can enter new info into them. I then I write that data to a new record
by using the following :- where ****TxtBox is the "Unbound" Text Box.

Private Sub SaveRecord()

Dim db As Database, rs1 As Recordset

Set db = CurrentDb
Set rs1 = db.OpenRecordset("tbl_Customer", dbOpenDynaset)
rs1.MoveLast
With rs1
.AddNew ' Add new record to end of Recordset
Object.
![Name] = NameTxtBox
![Addr1] = Addr1TxtBox
![Addr2] = Addr2TxtBox
Etc, Etc
.Update
End With
rs1.Close: db.Close

End Sub

If I could change the Text Box under Program control, it would save
duplicating all those extra boxes.

Or is there a better way to do it?

Thanks RayC

  #15  
Old August 31st, 2007, 08:50 AM posted to microsoft.public.access.gettingstarted
Ray C
external usenet poster
 
Posts: 215
Default Can I modify A Text Box under program control?

Hi John, sorry to be so long in coming back to you but is there a way of
"Aborting" the saving of the new record? Going back to my earlier notes, I
have a load of Text Boxes tha are "Bound " to the appropriat fields in the
Customers Table. These Text Boxes are great for finding and displaying
records in the table but any user will, at some time, want to add new records
to the table. The way I have approached this in the past is to generate a
parallel set of "Unbound" Text Boxes and use these to gather the new record
information. I then follow this by writing out the contents of each
individual "Unbound Text Box to a new record in the table using the "Save
record" routine I set out at the begining of my query after first asking the
user if they want to Save the data or Abort. I can also check for required
fields and prompt the user if any are not completed correctly. Your solution
is great in that it allows me to work with only one set of "Bound" text
boxes. However, the solution does seem somewhat flawed to me in that the user
says that they want to Add a New Record but there is no method by which the
user can subsequently say that they have made a mistake and have the option
not to save "Duff" information. Am I missing something here?
Your help is very much appreciated. RayC

"John Spencer" wrote:

Actually, it should save automatically. Access does that. I can't
remember why I put that bit in there - probably paranoia on my part.

'================================================= ===
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'================================================= ===


Ray C wrote:
Ahh, interesting, I will try to remember that.
With regard to your excelent solution to my problem, do I need to have
something that will save the record or will it save automatically. Also,
should I not be putting something in there that asks the user if they want to
save or not?

Regards RayC

"John Spencer" wrote:

The dirty bit forces a save of the current record if it has not yet been
saved.

'================================================= ===
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'================================================= ===


Ray C wrote:
Thanks John I will give it a try. Cureous about the "Dirty" bit though.

I realy appreciate your help. RayC

"John Spencer" wrote:

Add a button to your form "New Record"

In the click event add code to go to NEW Record.

THe code you need to add for the buttons click event should look
something like

On Error GoTo Err_sCmdAdd

With Me
If .Dirty = True Then .Dirty = False

If .AllowAdditions = False Then
.AllowAdditions = True
End If

DoCmd.GoToRecord , , acNewRec

End With

Exit_sCmdAdd:
Exit Function

Err_sCmdAdd:
MsgBox Err.Number & ": " & Err.Description,



'================================================= ===
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'================================================= ===


Ray C wrote:
It's only confusing because You know what I should be diong and I don't know
what I am doing :-)
I have a Form and I have Text Boxes on thst Form that are "Bound" to fields
in a Table. This is great if all I want to do is look at the information in
that Table but I might want to add a new record at some time and it is this
that I am working my way through. I don't have navigation Buttons on my Form
so I am not able to go to the last record and enter new information then
save. Could I do that under program control?
Hope this helps RayC

"scubadiver" wrote:

What are you trying to do? Sounds very confused to me.


--
The 11th day of every month:

http://truthaction.org/forum/index.php


"Ray C" wrote:

I have a number of "Bound" Text Boxes that display the appropriate records in
a Table (e.g. Mame, Address, etc) but I will want to add new records at some
time and I also Duplicate those same Text Boxes and have them "Unbound" so
that I can enter new info into them. I then I write that data to a new record
by using the following :- where ****TxtBox is the "Unbound" Text Box.

Private Sub SaveRecord()

Dim db As Database, rs1 As Recordset

Set db = CurrentDb
Set rs1 = db.OpenRecordset("tbl_Customer", dbOpenDynaset)
rs1.MoveLast
With rs1
.AddNew ' Add new record to end of Recordset
Object.
![Name] = NameTxtBox
![Addr1] = Addr1TxtBox
![Addr2] = Addr2TxtBox
Etc, Etc
.Update
End With
rs1.Close: db.Close

End Sub

If I could change the Text Box under Program control, it would save
duplicating all those extra boxes.

Or is there a better way to do it?

Thanks RayC


  #16  
Old August 31st, 2007, 12:02 PM posted to microsoft.public.access.gettingstarted
John Spencer
external usenet poster
 
Posts: 7,815
Default Can I modify A Text Box under program control?

You can always UNDO the entire record if the user doesn't want to save it.

The code for a cancel button would be
Me.Undo

If you are using subforms in conjunction with a main form to enter data into
multiple tables then this won't work since the minute you leave the main
form and enter the subform the data bound to the main form is saved. Also
when you leave a subform and go to the main form (or another subform) the
data bound to the subform is saved

You can use a form's before update event to check the data that is entered.
If your requirements aren't met you can generate a message to the user and
cancel the update (save) and force the user to enter satisfactory data.

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

"Ray C" wrote in message
...
Hi John, sorry to be so long in coming back to you but is there a way of
"Aborting" the saving of the new record? Going back to my earlier notes, I
have a load of Text Boxes tha are "Bound " to the appropriat fields in the
Customers Table. These Text Boxes are great for finding and displaying
records in the table but any user will, at some time, want to add new
records
to the table. The way I have approached this in the past is to generate a
parallel set of "Unbound" Text Boxes and use these to gather the new
record
information. I then follow this by writing out the contents of each
individual "Unbound Text Box to a new record in the table using the "Save
record" routine I set out at the begining of my query after first asking
the
user if they want to Save the data or Abort. I can also check for required
fields and prompt the user if any are not completed correctly. Your
solution
is great in that it allows me to work with only one set of "Bound" text
boxes. However, the solution does seem somewhat flawed to me in that the
user
says that they want to Add a New Record but there is no method by which
the
user can subsequently say that they have made a mistake and have the
option
not to save "Duff" information. Am I missing something here?
Your help is very much appreciated. RayC

"John Spencer" wrote:

Actually, it should save automatically. Access does that. I can't
remember why I put that bit in there - probably paranoia on my part.

'================================================= ===
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'================================================= ===


Ray C wrote:
Ahh, interesting, I will try to remember that.
With regard to your excelent solution to my problem, do I need to have
something that will save the record or will it save automatically.
Also,
should I not be putting something in there that asks the user if they
want to
save or not?

Regards RayC

"John Spencer" wrote:

The dirty bit forces a save of the current record if it has not yet
been
saved.

'================================================= ===
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'================================================= ===


Ray C wrote:
Thanks John I will give it a try. Cureous about the "Dirty" bit
though.

I realy appreciate your help. RayC

"John Spencer" wrote:

Add a button to your form "New Record"

In the click event add code to go to NEW Record.

THe code you need to add for the buttons click event should look
something like

On Error GoTo Err_sCmdAdd

With Me
If .Dirty = True Then .Dirty = False

If .AllowAdditions = False Then
.AllowAdditions = True
End If

DoCmd.GoToRecord , , acNewRec

End With

Exit_sCmdAdd:
Exit Function

Err_sCmdAdd:
MsgBox Err.Number & ": " & Err.Description,



'================================================= ===
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'================================================= ===


Ray C wrote:
It's only confusing because You know what I should be diong and I
don't know
what I am doing :-)
I have a Form and I have Text Boxes on thst Form that are "Bound"
to fields
in a Table. This is great if all I want to do is look at the
information in
that Table but I might want to add a new record at some time and it
is this
that I am working my way through. I don't have navigation Buttons
on my Form
so I am not able to go to the last record and enter new information
then
save. Could I do that under program control?
Hope this helps RayC

"scubadiver" wrote:

What are you trying to do? Sounds very confused to me.


--
The 11th day of every month:

http://truthaction.org/forum/index.php


"Ray C" wrote:

I have a number of "Bound" Text Boxes that display the
appropriate records in
a Table (e.g. Mame, Address, etc) but I will want to add new
records at some
time and I also Duplicate those same Text Boxes and have them
"Unbound" so
that I can enter new info into them. I then I write that data to
a new record
by using the following :- where ****TxtBox is the "Unbound" Text
Box.

Private Sub SaveRecord()

Dim db As Database, rs1 As Recordset

Set db = CurrentDb
Set rs1 = db.OpenRecordset("tbl_Customer", dbOpenDynaset)
rs1.MoveLast
With rs1
.AddNew ' Add new record to end of
Recordset
Object.
![Name] = NameTxtBox
![Addr1] = Addr1TxtBox
![Addr2] = Addr2TxtBox
Etc, Etc
.Update
End With
rs1.Close: db.Close

End Sub

If I could change the Text Box under Program control, it would
save
duplicating all those extra boxes.

Or is there a better way to do it?

Thanks RayC




  #17  
Old August 31st, 2007, 01:10 PM posted to microsoft.public.access.gettingstarted
Ray C
external usenet poster
 
Posts: 215
Default Can I modify A Text Box under program control?

John, Your a Gem !!! :-)
I will check that out, I did not realise that it updated as you moved from
the Form and never thought about the Forms Update Event.
Once again, your a Star!! Regards RayC


"John Spencer" wrote:

You can always UNDO the entire record if the user doesn't want to save it.

The code for a cancel button would be
Me.Undo

If you are using subforms in conjunction with a main form to enter data into
multiple tables then this won't work since the minute you leave the main
form and enter the subform the data bound to the main form is saved. Also
when you leave a subform and go to the main form (or another subform) the
data bound to the subform is saved

You can use a form's before update event to check the data that is entered.
If your requirements aren't met you can generate a message to the user and
cancel the update (save) and force the user to enter satisfactory data.

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

"Ray C" wrote in message
...
Hi John, sorry to be so long in coming back to you but is there a way of
"Aborting" the saving of the new record? Going back to my earlier notes, I
have a load of Text Boxes tha are "Bound " to the appropriat fields in the
Customers Table. These Text Boxes are great for finding and displaying
records in the table but any user will, at some time, want to add new
records
to the table. The way I have approached this in the past is to generate a
parallel set of "Unbound" Text Boxes and use these to gather the new
record
information. I then follow this by writing out the contents of each
individual "Unbound Text Box to a new record in the table using the "Save
record" routine I set out at the begining of my query after first asking
the
user if they want to Save the data or Abort. I can also check for required
fields and prompt the user if any are not completed correctly. Your
solution
is great in that it allows me to work with only one set of "Bound" text
boxes. However, the solution does seem somewhat flawed to me in that the
user
says that they want to Add a New Record but there is no method by which
the
user can subsequently say that they have made a mistake and have the
option
not to save "Duff" information. Am I missing something here?
Your help is very much appreciated. RayC

"John Spencer" wrote:

Actually, it should save automatically. Access does that. I can't
remember why I put that bit in there - probably paranoia on my part.

'================================================= ===
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'================================================= ===


Ray C wrote:
Ahh, interesting, I will try to remember that.
With regard to your excelent solution to my problem, do I need to have
something that will save the record or will it save automatically.
Also,
should I not be putting something in there that asks the user if they
want to
save or not?

Regards RayC

"John Spencer" wrote:

The dirty bit forces a save of the current record if it has not yet
been
saved.

'================================================= ===
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'================================================= ===


Ray C wrote:
Thanks John I will give it a try. Cureous about the "Dirty" bit
though.

I realy appreciate your help. RayC

"John Spencer" wrote:

Add a button to your form "New Record"

In the click event add code to go to NEW Record.

THe code you need to add for the buttons click event should look
something like

On Error GoTo Err_sCmdAdd

With Me
If .Dirty = True Then .Dirty = False

If .AllowAdditions = False Then
.AllowAdditions = True
End If

DoCmd.GoToRecord , , acNewRec

End With

Exit_sCmdAdd:
Exit Function

Err_sCmdAdd:
MsgBox Err.Number & ": " & Err.Description,



'================================================= ===
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'================================================= ===


Ray C wrote:
It's only confusing because You know what I should be diong and I
don't know
what I am doing :-)
I have a Form and I have Text Boxes on thst Form that are "Bound"
to fields
in a Table. This is great if all I want to do is look at the
information in
that Table but I might want to add a new record at some time and it
is this
that I am working my way through. I don't have navigation Buttons
on my Form
so I am not able to go to the last record and enter new information
then
save. Could I do that under program control?
Hope this helps RayC

"scubadiver" wrote:

What are you trying to do? Sounds very confused to me.


--
The 11th day of every month:

http://truthaction.org/forum/index.php


"Ray C" wrote:

I have a number of "Bound" Text Boxes that display the
appropriate records in
a Table (e.g. Mame, Address, etc) but I will want to add new
records at some
time and I also Duplicate those same Text Boxes and have them
"Unbound" so
that I can enter new info into them. I then I write that data to
a new record
by using the following :- where ****TxtBox is the "Unbound" Text
Box.

Private Sub SaveRecord()

Dim db As Database, rs1 As Recordset

Set db = CurrentDb
Set rs1 = db.OpenRecordset("tbl_Customer", dbOpenDynaset)
rs1.MoveLast
With rs1
.AddNew ' Add new record to end of
Recordset
Object.
![Name] = NameTxtBox
![Addr1] = Addr1TxtBox
![Addr2] = Addr2TxtBox
Etc, Etc
.Update
End With
rs1.Close: db.Close

End Sub

If I could change the Text Box under Program control, it would
save
duplicating all those extra boxes.

Or is there a better way to do it?

Thanks RayC





  #18  
Old August 31st, 2007, 02:06 PM posted to microsoft.public.access.gettingstarted
Ray C
external usenet poster
 
Posts: 215
Default Can I modify A Text Box under program control?

Hi Jojn
Sorry about draging this on but I am actualy using my Main Form to look at
data held in two Tables but I do this with a Query rather than a Sub Form (my
Form is "Bound" to the Query) This works fine to read the records and it
should work with new save providing I write somthing else to save the
"Primary ID" in the Secondary ID's, ID (if you know what I mean). All
customers are in the Main Customer Table (Primary Key is Auto number) but
some Customers have "Extra Info" held in the "Customers_Extra_Info" Table
with a non AutoNumber ID.
I will let you know.
RayC

"Ray C" wrote:

John, Your a Gem !!! :-)
I will check that out, I did not realise that it updated as you moved from
the Form and never thought about the Forms Update Event.
Once again, your a Star!! Regards RayC


"John Spencer" wrote:

You can always UNDO the entire record if the user doesn't want to save it.

The code for a cancel button would be
Me.Undo

If you are using subforms in conjunction with a main form to enter data into
multiple tables then this won't work since the minute you leave the main
form and enter the subform the data bound to the main form is saved. Also
when you leave a subform and go to the main form (or another subform) the
data bound to the subform is saved

You can use a form's before update event to check the data that is entered.
If your requirements aren't met you can generate a message to the user and
cancel the update (save) and force the user to enter satisfactory data.

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

"Ray C" wrote in message
...
Hi John, sorry to be so long in coming back to you but is there a way of
"Aborting" the saving of the new record? Going back to my earlier notes, I
have a load of Text Boxes tha are "Bound " to the appropriat fields in the
Customers Table. These Text Boxes are great for finding and displaying
records in the table but any user will, at some time, want to add new
records
to the table. The way I have approached this in the past is to generate a
parallel set of "Unbound" Text Boxes and use these to gather the new
record
information. I then follow this by writing out the contents of each
individual "Unbound Text Box to a new record in the table using the "Save
record" routine I set out at the begining of my query after first asking
the
user if they want to Save the data or Abort. I can also check for required
fields and prompt the user if any are not completed correctly. Your
solution
is great in that it allows me to work with only one set of "Bound" text
boxes. However, the solution does seem somewhat flawed to me in that the
user
says that they want to Add a New Record but there is no method by which
the
user can subsequently say that they have made a mistake and have the
option
not to save "Duff" information. Am I missing something here?
Your help is very much appreciated. RayC

"John Spencer" wrote:

Actually, it should save automatically. Access does that. I can't
remember why I put that bit in there - probably paranoia on my part.

'================================================= ===
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'================================================= ===


Ray C wrote:
Ahh, interesting, I will try to remember that.
With regard to your excelent solution to my problem, do I need to have
something that will save the record or will it save automatically.
Also,
should I not be putting something in there that asks the user if they
want to
save or not?

Regards RayC

"John Spencer" wrote:

The dirty bit forces a save of the current record if it has not yet
been
saved.

'================================================= ===
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'================================================= ===


Ray C wrote:
Thanks John I will give it a try. Cureous about the "Dirty" bit
though.

I realy appreciate your help. RayC

"John Spencer" wrote:

Add a button to your form "New Record"

In the click event add code to go to NEW Record.

THe code you need to add for the buttons click event should look
something like

On Error GoTo Err_sCmdAdd

With Me
If .Dirty = True Then .Dirty = False

If .AllowAdditions = False Then
.AllowAdditions = True
End If

DoCmd.GoToRecord , , acNewRec

End With

Exit_sCmdAdd:
Exit Function

Err_sCmdAdd:
MsgBox Err.Number & ": " & Err.Description,



'================================================= ===
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'================================================= ===


Ray C wrote:
It's only confusing because You know what I should be diong and I
don't know
what I am doing :-)
I have a Form and I have Text Boxes on thst Form that are "Bound"
to fields
in a Table. This is great if all I want to do is look at the
information in
that Table but I might want to add a new record at some time and it
is this
that I am working my way through. I don't have navigation Buttons
on my Form
so I am not able to go to the last record and enter new information
then
save. Could I do that under program control?
Hope this helps RayC

"scubadiver" wrote:

What are you trying to do? Sounds very confused to me.


--
The 11th day of every month:

http://truthaction.org/forum/index.php


"Ray C" wrote:

I have a number of "Bound" Text Boxes that display the
appropriate records in
a Table (e.g. Mame, Address, etc) but I will want to add new
records at some
time and I also Duplicate those same Text Boxes and have them
"Unbound" so
that I can enter new info into them. I then I write that data to
a new record
by using the following :- where ****TxtBox is the "Unbound" Text
Box.

Private Sub SaveRecord()

Dim db As Database, rs1 As Recordset

Set db = CurrentDb
Set rs1 = db.OpenRecordset("tbl_Customer", dbOpenDynaset)
rs1.MoveLast
With rs1
.AddNew ' Add new record to end of
Recordset
Object.
![Name] = NameTxtBox
![Addr1] = Addr1TxtBox
![Addr2] = Addr2TxtBox
Etc, Etc
.Update
End With
rs1.Close: db.Close

End Sub

If I could change the Text Box under Program control, it would
save
duplicating all those extra boxes.

Or is there a better way to do it?

Thanks RayC





 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:20 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.