473,401 Members | 2,125 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,401 software developers and data experts.

Updating Two Check Boxes on a Form from A Choice in another Combo Box

Hello,

My infamous manufacturing database continues to bane my life, mostly
because I'm really stumbling around in the dark here!

What I am trying to do is populate some fields automatically dependent
on choices made elsewhere, I'll set the scene:

Users take a PCB off of the production line and put it through our
testing mechanisms. At present it is logged on a peice of paper and
then exceled into a report, which takes ages and is rubbish.

Now they will have this database I am 'attempting' to create to do the
hard part for them, i.e. using a pen and creating reports.

Problem 1:

They need to log the fault type from a list of 6 possible problems, one
of these is 'Pass'. If this is chosen then I want the Pass tickbox at
the end of the row to be checked, and the Fail one to be un-checked.

If anything else is chosen then the reverse of this should happen.

So far the code I've got in for the afterupdate event on the combobox
is this:

Private Sub Fault_Description_AfterUpdate()
If Me![Fault_Description] = Pass Then
Me![Pass] = -1 And Me![Fail] = 0
Else
Me![Pass] = 0 And Me![Fail] = -1
End If
End Sub

I've tried a few variations of this, but so far nothing, and as you're
probably now aware I have NO idea what I'm doing, except for a basic
grasp of the concepts!

Problem 2:

I wanted to create the number of records on my continous form
automatically for the user, and numbered in the 'serial_number' field
as well. So the user enters '50' into a box somewhere, and hits a
button which automatically adds 50 records on my continuous faults
subform against my batch number and user name on the main form.

I've got some distance with automatic numbering using the dmax funtion,
but it just doesnt cut it. The problem is the next user who comes
along would be using serial numbers 51-100, and this is of no use, it
has to start from 1-x again as the first test would have.

I realise I'm asking a shed load here, so any advise other than 'buy a
book' which I've already done several times! Would be much appreciated.

Cheers,

Chris.

Nov 13 '05 #1
11 1614
Rog
1. If Fault_Description is a text field, you need to put "Pass"
between quotation marks. (BTW, why do you have a Pass and a Fail
checkbox? Does an item not automatically fail if it does not pass, and
vice versa?)

2. You need to use a loop to create records, e.g. (air code)

dim mydb as database, myset as recordset, x as long
set mydb = currentdb()
set myset = mydb.OpenRecordset("tblFaults",dbOpenDynaset)
for x = 1 to Me!myNumberBox
myset.AddNew
myset("SerialNumber") =x
myset.Update
next
myset.close
set myset=nothing
set mydb=nothing

Nov 13 '05 #2
I think i'm way out of my depth here, I dont really know much about
VBA.

The example I gave above doesnt work at all, even with "pass" written
into it.

Instead of the field names I'm trying to change I've also tried
referencing the check boxes on the form directly, but that doesnt work
either..

And then I've tried the code that Rog put above for the other things I
want to do and just get compile errors!

Nov 13 '05 #3
Ok, I've got a little further with my 2nd problem, the reason I have 2
tick boxes by the way is to do with the reports side not liking it when
I only have one and counting the totals..

As for the 2nd prob:

Private Sub Command38_Click()

Dim mydb As database, myset As Recordset, x As Long
Set mydb = CurrentDb()
Set myset = mydb.OpenRecordset("Faults", dbOpenDynaset)
For x = 1 To Me!AutoNum
myset.AddNew
myset("SerialNumber") = x
myset.Update
Next
myset.Close
Set myset = Nothing
Set mydb = Nothing

End Sub

Gets to the third line before giving me a type mismatch error - could
this be to do with the recordset name? As I just put the table name in
that its referring too, in this case 'Faults'

As usual, help much appreciated in advance :)

Chris.

Nov 13 '05 #4
ch****@cemgraft.co.uk wrote:
Problem 1:

Private Sub Fault_Description_AfterUpdate()
If Me![Fault_Description] = Pass Then
Me![Pass] = -1 And Me![Fail] = 0
Else
Me![Pass] = 0 And Me![Fail] = -1
End If
End Sub
This is being done on a form, I presume.

To do exactly what you seem to be describing above, do the following:

Private Sub Fault_Description_AfterUpdate()

If Me![Fault_Description] = "Pass" Then

Me![Pass] = -1
Me![Fail] = 0

Else

Me![Pass] = 0
Me![Fail] = -1

End If

End Sub

However, why not just use an option group (fraPassFail in the example
below) with two check marks? You could have the "pass" check mark have
a value of 1 and the "fail" check mark have a value of 2 and then,
presumeably, this information would be stored in a table in which the
field names are pass and fail (I generally use the dot. notation as
opposed to the bang!:

Private sub fraPassFail_AfterUpdate()

if me.fraPassFail = 1 then
Me.Pass = -1
Me.Fail = 0

Else

Me.Pass = 0
Me.Fail = -1

End If

end sub
Problem 2:


Don't have time to make a suggestion, now, sorry.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Nov 13 '05 #5
On second thought, as Rog hints, it's just plain stupid to have a Pass
and a Fail field for data. Have the one field, Pass and use, in the
option group example:

Private sub fraPassFail_AfterUpdate()

if me.fraPassFail = 1 then me.pass = -1 else me.pass = 0

end sub

While your users will want two choices on their form, if you have this
in your structure, then you might as well just stick with spreadsheets. 8)

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Nov 13 '05 #6
Ok, problem one is now done and dusted, and is working absolutley
brilliantly - many thanks to all for that one :D

Still need to sort my problem with the adding records automatically.

Last night I got it to add the records depending on the amount entered
into the field 'autonum' however it wasnt linking back to the master
records, it was just entering new lines into the faults table, which is
supposed to link to products and then back to batches..

Then I got to another stage where the error was actually telling me
that I couldnt enter records as there was no corresponding record in
the products table...

So I'm in limbo again at this point in time, and if anyones had to do
something like this before, or knows how to I would be forever
greatful!

Cheers,

Chris.

Nov 13 '05 #7
Rog
Chris,

Does your main form have products as its data source? If so, you will
have to save a newly entered record first before running the code that
creates fault records. Just add the following line:
RunCommand acCmdSaveRecord
before running the procedure that creates your subform records.

On the other hand, if products is not your data source, you can create
your product record by code, similar to the code I gave you to create
the fault records (except that you don't need the for...next loop).
Something like:
set myset2 = mydb.OpenRecordset("Products"*,dbOpenDynaset)
myset2.AddNew
myset2("somefield") = something
myset2("someotherfield") = somethingelse
myset2.Update
myset2.Close
set myset2=nothing

Nov 13 '05 #8
Hi Rog,

The tables are:

Batch Detail where 'Batch_ID' is the Primary Key, and an Autonumber.
This is linked to a table called 'Products' where 'Product_ID' is the
Primary Key, which in turn is linked to the Faults table with Primay
Key of Fault_ID.

The main form incorporates both the Batch and Product Table. Users
Select their name which generates the new Batch_ID number, choose a
product they are testing which Generates the Product_ID and then enter
the faults on the subform. The subform knows how to link the faults by
using the Product_ID against each fault logged..

Does that make sence?

I'm going to have a go with that code for saving and see if I can get
that going...

As always, much appreciated.

Chris.

Nov 13 '05 #9
Right, so this is my code at the moment, on the button which is on the
Products/main form:

Private Sub Command38_Click()
RunCommand acCmdSaveRecord
Dim mydb As Database, myset As Recordset, x As Long
Set mydb = CurrentDb()
Set myset = mydb.OpenRecordset("Faults", dbOpenDynaset)
For x = 1 To Me!AutoNum
myset.AddNew
myset("SerialNumber") = x
myset.Update
Next
myset.Close
Set myset = Nothing
Set mydb = Nothing
End Sub

It falls down on this line: Set myset = mydb.OpenRecordset("Faults",
dbOpenDynaset)

With a type mismatch error, and when I hover over it it says
myset=nothing..

Now I did get around this yesterday, but cant for the life of me
remember how, I need to hit the books I think!

Chris.

Nov 13 '05 #10
Ok, that was something to do with ADO references, so thats fixed and
now im back to this error:

Run-time error '3201':

You cannot add or change a record because a related record is required
in table 'Products'.

Do I need to code in somewhere that the primary key for faults = a
value in the products table, or would it do that of its own accord? Or
am I way of piste...

Cheers,

Chris.

Nov 13 '05 #11
Woohoo,

Got it working, I'm forever happy! Thanks to everyone that helped,
heres the code that worked if you're interested, its all yours really
Rog!

Private Sub Command38_Click()
RunCommand acCmdSaveRecord
Dim mydb As Database, myset As Recordset, x As Long
Set mydb = DBEngine.Workspaces(0).Databases(0)
Set myset = mydb.OpenRecordset("Faults", dbOpenDynaset)
For x = 1 To Me!AutoNum
myset.AddNew
myset("Serial Number") = x
myset("Fault_ID") = Me.Product_List_ID
RunCommand acCmdSaveRecord
myset.Update
Next x
Me.Recalc
myset.Close
Set myset = Nothing
Set mydb = Nothing
End Sub

Cheers,

Chris.

Nov 13 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ryan.Chowdhury | last post by:
This is a general question regarding the use of view and stored procedures. I'm fairly new to databases and SQL. I've created a SQL database using an Access Data Project ("ADP") and I'm...
2
by: Stephen Miller | last post by:
I have a page with many, dynamically generated combo boxes and I want to check all of them, before I add a unique value to specific combo. What would be the best way to work through the document...
5
by: J. Yuan | last post by:
Hi, I am working on a checkout/inventory system. How can I make a button that when pressed, would update the previous fields transaction number to a table (for example, -3 printers, so that...
6
by: rad | last post by:
I am stuck with this problem. I need to create form with checkbox that must be populated dynamically from a table. For example, if I have a table called Fruits, and the values are "Apple",...
5
by: Shreekant Patel | last post by:
Hello, I am new to the advanced level of access, and I have quite a few changes to make to an existing database. The current database's main form needs to have additional check boxes added to...
6
by: Dave | last post by:
I want to put the information that the user selects in my combo boxes into a subform that lies on the same form as the combo boxes. Thanks for your help already, Dave
9
by: Marianne160 | last post by:
Hi, I know there are various answers to this problem available on the web but none of them seem to work for me. I am using Access 2003 to make a form to look up data from a table. I have so far...
11
by: seangibson | last post by:
Sorry, I've been posting alot of questions regarding cascaded combo boxes here but each time I solve one problem I seem to be faced with a new. This time here's the problem: I've got the combo...
12
by: Lnwolf | last post by:
Hello, I am having an issue with my synchronized combo boxes and don't know how to fix it. I have created two boxes and have made the synchronization work (the user clicks on the first box and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.