473,386 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to update selected records on a datasheet subform using seltop and selheight?

176 100+
Hello to all.

In what way can I update a certain selected records' values on a datasheet subform using a command button which is located on the main form?

Thanks and cheers.
Jan 14 '07 #1
10 13345
nico5038
3,080 Expert 2GB
You can construct an UPDATE query in the mainform buttons' OnClick event, using an additional textfield on the mainform named txtNewValue, like:

currentdb.execute ("Update tblX Set TextFieldA='" & me.txtNewValue & "' where ID=" & me.subformname.form.ID)

or for a number:

currentdb.execute ("Update tblX Set NumberFieldB=" & me.txtNewValue & " WHERE ID=" & me.subformname.form.ID)

The ".subformname.form" is needed to refer to the unique key of the current record of the subform. Ofcourse you need to change the name to the name of your subform....
Getting the idea?

Nic;o)
Jan 14 '07 #2
Michael R
176 100+
You can construct an UPDATE query in the mainform buttons' OnClick event, using an additional textfield on the mainform named txtNewValue, like:

currentdb.execute ("Update tblX Set TextFieldA='" & me.txtNewValue & "' where ID=" & me.subformname.form.ID)

or for a number:

currentdb.execute ("Update tblX Set NumberFieldB=" & me.txtNewValue & " WHERE ID=" & me.subformname.form.ID)

The ".subformname.form" is needed to refer to the unique key of the current record of the subform. Ofcourse you need to change the name to the name of your subform....
Getting the idea?

Nic;o)
Nope, I'm talking about several records selection.
When I make a selection using the mouse on the datasheet subform, I need a button to be able to update the selected values. Problem is, as I press button on the main form, the focus dissaperas from the selection and the selection drops.
Jan 14 '07 #3
nico5038
3,080 Expert 2GB
You'll need the subform's OnCurrent event with code like:

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

On Error Resume Next

Parent.txtSelLength = Me.SelHeight
Parent.txtSelstart = Me.SelTop

Dim rs As Recordset
Dim intI As Integer

Set rs = Me.RecordsetClone

rs.MoveFirst
intI = 1
While intI < Me.SelTop
intI = intI + 1
rs.MoveNext
Wend
'now positioned on the first

'Init resultfield
Parent.txtSelected = ""

intI = 0

While intI < Me.SelHeight
Parent.txtSelected = Parent.txtSelected & " " & rs!Field1
intI = intI + 1
rs.MoveNext
Wend

Set rs = Nothing

End Sub

When you place the Parent.txt... fields on your mainform and change rs!field1 into the name of your keyfield, then you'll see the effect. (Make sure you have a reference set to the DAO library)

Nic;o)
Jan 15 '07 #4
Michael R
176 100+
You'll need the subform's OnCurrent event with code like:

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

On Error Resume Next

Parent.txtSelLength = Me.SelHeight
Parent.txtSelstart = Me.SelTop

Dim rs As Recordset
Dim intI As Integer

Set rs = Me.RecordsetClone

rs.MoveFirst
intI = 1
While intI < Me.SelTop
intI = intI + 1
rs.MoveNext
Wend
'now positioned on the first

'Init resultfield
Parent.txtSelected = ""

intI = 0

While intI < Me.SelHeight
Parent.txtSelected = Parent.txtSelected & " " & rs!Field1
intI = intI + 1
rs.MoveNext
Wend

Set rs = Nothing

End Sub

When you place the Parent.txt... fields on your mainform and change rs!field1 into the name of your keyfield, then you'll see the effect. (Make sure you have a reference set to the DAO library)

Nic;o)
Thanks Nico, I've tried that, and it works, but I was asking about how can I update a selection of several records from a datasheet subform in the following way:

subform:.....field1.....field2
......................1..........true
......................2..........true
> ...................3..........true
> ...................4..........true

so, if the selection will is 3-4 then by using the command button from the main form, i need the subform to be changed to this:

subform:.....field1.....field2
......................1..........true
......................2..........true
......................3..........false
......................4..........false

the main reason I can't figure out how to do it, except the fact that I don't understand very well the mechanics of working with recordsets, is because as I select several records from the subform, and press the command button, the records are being dis-selected because the subform losts the focus.
Jan 15 '07 #5
nico5038
3,080 Expert 2GB
The above code can be used to collect the unique ID's of the subform and these can be used to issue UPDATE queries like:

dim arr
dim intI as integer

ass = split (me.txtKeyFields,",")

for intI = 0 to UBOUND(arr)
currentdb.execute ("update tblX set YesNo=Not(YesNo) where KeyField=" & arr(intI))
next

Getting the idea ?

Nic;o)
Jan 15 '07 #6
Michael R
176 100+
The above code can be used to collect the unique ID's of the subform and these can be used to issue UPDATE queries like:

dim arr
dim intI as integer

ass = split (me.txtKeyFields,",")

for intI = 0 to UBOUND(arr)
currentdb.execute ("update tblX set YesNo=Not(YesNo) where KeyField=" & arr(intI))
next

Getting the idea ?

Nic;o)
Yep, it works using a public array for collecting unique id's (I didn't understand how to do it using Parent.txt....),

Thanks very much.
Jan 15 '07 #7
Michael R
176 100+
Nico, something additional on this issue

While this method works great on a subform, it doesn't work well with a regular continous form. It doesn't always recognize the selection. Maybe it is has something to do with timing issues? Do you know how can I work this out?

Thanks again.
Jan 15 '07 #8
nico5038
3,080 Expert 2GB
Do you have a timer coded somewhere?
If so, that could be the reason as a timer will disturb the focussing and event sequence.

Nic;o)
Jan 16 '07 #9
Michael R
176 100+
Do you have a timer coded somewhere?
If so, that could be the reason as a timer will disturb the focussing and event sequence.

Nic;o)
No, the code is timer-free
I change the subform event of the collecting id's code to On Mouse Up, and it works fine.

Cheers, Michael.
Jan 17 '07 #10
nico5038
3,080 Expert 2GB
I wrote OnCurrent and coded the MouseUp sorry.... :-)

Success with your application !

Nic;o)
Jan 17 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Kunal | last post by:
Hi, I need some help on writing an update query to update "UnitsSold" field in Products Table whenever I save a transaction. The transaction may contain several "Subtransactions", one for each...
3
by: CLarkou | last post by:
Is there any way to get the record(s) the user has selected in a Datasheet form ?
3
by: deko | last post by:
I have a form with a subform datasheet - I need code behind the OnDelete event of the subform: Private Sub Form_Delete(Cancel As Integer) 'do something that depends on which record is deleted...
1
by: sofakingfree | last post by:
Is there a way to perform actions on the selected records of a datasheet subform? Actually I know it can be done from a pulldown menu or a toolbar. But how can you create a button on the form...
1
by: Thomas Zimmermann | last post by:
I have a form with a subform in datasheet view. Now, I want to trigger a procedure (P1) each time the user selects an entire column (by clicking in the heading) in the subform. The procedure (P1) I...
4
dima69
by: dima69 | last post by:
Is it possible to select multiple records on datasheet via code ? Using SelTop and SelHeight properties dosn't give the same result as selecting the records manually, since record selectors remain...
7
by: dscarbor | last post by:
I have a simple form with 4 fields, and a subform that retrieves records that are potential matches based on a query. The user will use the ID from the subform record and enter it into one of the...
1
by: Coll | last post by:
I have a form with a subform on it. On my main form, you select an employee id number and the top portion of form fills in with data, and the bottom portion of the form,which is a subform, lists...
1
by: RamanS | last post by:
Hi, I am creating an inventory management database. I have three tables in this database, Products, Orders and Order Details. I have a form Order Entry in which i create an order to be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.