PC Review


Reply
Thread Tools Rate Thread

How can I change the value of checkbox using VBA?

 
 
=?Utf-8?B?UklQ?=
Guest
Posts: n/a
 
      24th Apr 2006
Thanks in advance.

Here is what I am trying to accomplish...

How can I change the value of the "active" checkbox in tblInventory for a
vehicle that just sold by just clicking on the "save" button on the
frmVehicleSale.

I am using frmVehicleSale to add a recordset (containing all the sale
details) to the tblVehicleSale. After updating the recordset I want to go in
to tblInventory and change the value of the "active" checkbox for the vehicle
that just sold from being true to being false, to filter it out of active
inventory.

The field "stockno" is the common field in both tables;however it is not the
primary key in tblInventory. The primary key in tblInventory is "ctrlno".

The code for the "save" button in "frmVehicleSale" looks like this:

Private Sub save_sale_Click()
Dim db As DAO.Database
Dim rctSaveSale As DAO.Recordset

'*** Create a pointer to the database and a pointer to the table ***
Set db = CurrentDb()
Set rctSaveSale = db.OpenRecordset("tblVehicleSale", dbOpenTable)

rctSaveSale.AddNew
rctSaveSale!ctrlno = ctrlno
rctSaveSale!saledate = saledate
rctSaveSale!dlrname = dlrname
rctSaveSale!cusname = cusname
rctSaveSale!stockno = stockno
rctSaveSale!vsprice = vsprice
rctSaveSale!vstrade = vstrade
rctSaveSale!vsstax = vsstax
rctSaveSale!vsinvtax = vsinvtax
rctSaveSale!vsaufee = vsaufee
rctSaveSale!vscrbafee = vscrbafee
rctSaveSale!vscsfee = vscsfee
rctSaveSale!vsdocfee = vsdocfee
rctSaveSale!vsrebfee = vsrebfee
rctSaveSale!vsregfee = vsregfee
rctSaveSale!vsreffee = vsreffee
rctSaveSale!vstitfee = vstitfee
rctSaveSale!vstrafee = vstrafee
rctSaveSale!vswinstk = vswinstk
rctSaveSale!vsvehins = vsvehins
rctSaveSale!vsothr01 = ChangeNulltoBlank(vsothr01)
rctSaveSale!vsothr02 = ChangeNulltoBlank(vsothr02)
rctSaveSale!vsothr03 = ChangeNulltoBlank(vsothr03)
rctSaveSale!vsothr04 = ChangeNulltoBlank(vsothr04)
rctSaveSale!vsdep01 = ChangeNulltoBlank(vsdep01)
rctSaveSale.Update
DoCmd.Close
rctSaveSale.Close
db.Close
End Sub


 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWFydGlu?=
Guest
Posts: n/a
 
      24th Apr 2006
The following should do it - I've added a couple of Dims which should join
your exising ones then, after your record's been updated, I've set the query
definition object's SQL statement to an update query (I just copied this from
the SQL view of an update query and substituted the value of your stockno
into it - beware of the quote marks). This query is then executed (by giving
it no name it only exists in the macro and doesn't appear as a real query in
your database).


Dim qry As DAO.QueryDef
Dim str As String

[your code down to:]
rctSaveSale.Update

str = "UPDATE tblInventory SET chkActive = False WHERE (((stockno)=" &
rctSaveSale!stockno & "));"
Set qry = db.CreateQueryDef("")
qry.SQL = str
qry.Execute

[rest of your code]

"RIP" wrote:

> Thanks in advance.
>
> Here is what I am trying to accomplish...
>
> How can I change the value of the "active" checkbox in tblInventory for a
> vehicle that just sold by just clicking on the "save" button on the
> frmVehicleSale.
>
> I am using frmVehicleSale to add a recordset (containing all the sale
> details) to the tblVehicleSale. After updating the recordset I want to go in
> to tblInventory and change the value of the "active" checkbox for the vehicle
> that just sold from being true to being false, to filter it out of active
> inventory.
>
> The field "stockno" is the common field in both tables;however it is not the
> primary key in tblInventory. The primary key in tblInventory is "ctrlno".
>
> The code for the "save" button in "frmVehicleSale" looks like this:
>
> Private Sub save_sale_Click()
> Dim db As DAO.Database
> Dim rctSaveSale As DAO.Recordset
>
> '*** Create a pointer to the database and a pointer to the table ***
> Set db = CurrentDb()
> Set rctSaveSale = db.OpenRecordset("tblVehicleSale", dbOpenTable)
>
> rctSaveSale.AddNew
> rctSaveSale!ctrlno = ctrlno
> rctSaveSale!saledate = saledate
> rctSaveSale!dlrname = dlrname
> rctSaveSale!cusname = cusname
> rctSaveSale!stockno = stockno
> rctSaveSale!vsprice = vsprice
> rctSaveSale!vstrade = vstrade
> rctSaveSale!vsstax = vsstax
> rctSaveSale!vsinvtax = vsinvtax
> rctSaveSale!vsaufee = vsaufee
> rctSaveSale!vscrbafee = vscrbafee
> rctSaveSale!vscsfee = vscsfee
> rctSaveSale!vsdocfee = vsdocfee
> rctSaveSale!vsrebfee = vsrebfee
> rctSaveSale!vsregfee = vsregfee
> rctSaveSale!vsreffee = vsreffee
> rctSaveSale!vstitfee = vstitfee
> rctSaveSale!vstrafee = vstrafee
> rctSaveSale!vswinstk = vswinstk
> rctSaveSale!vsvehins = vsvehins
> rctSaveSale!vsothr01 = ChangeNulltoBlank(vsothr01)
> rctSaveSale!vsothr02 = ChangeNulltoBlank(vsothr02)
> rctSaveSale!vsothr03 = ChangeNulltoBlank(vsothr03)
> rctSaveSale!vsothr04 = ChangeNulltoBlank(vsothr04)
> rctSaveSale!vsdep01 = ChangeNulltoBlank(vsdep01)
> rctSaveSale.Update
> DoCmd.Close
> rctSaveSale.Close
> db.Close
> End Sub
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Checkbox does not change Stefan Hoffmann Microsoft Access 0 17th Jul 2009 01:23 PM
checkbox value change pv78 Microsoft Excel Programming 4 16th Aug 2006 04:49 PM
Master-Detail Datagrid -checkbox (once tick the checkbox, all the child checkbox is ticked) Agnes Microsoft VB .NET 0 16th Aug 2004 11:23 AM
Change checkbox value Trevor Microsoft Access 3 16th Aug 2004 07:18 AM
Change checkbox value... Kazoo Microsoft Excel Worksheet Functions 2 22nd Oct 2003 11:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:17 PM.