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

Record Set will not set new value to allocated field

16
In a form I have a bound object that is related to a field (Batch Number) within this table called tblDrumResults.

What I would like for it to do is by choosing a batch number to automatically populate the next field underneath batch number which is kiln.

The criteria for this is that I need to find the batch number that is equivalent to the current batch number I have in another database, in another table called "tblKilnData", because that database currently holds the kiln value I need. So once I have found where the batch number is the same, I need to see in that particular record what the value is for the Kiln Set (another word for Kiln field). If the value for Kiln Set = 11 I need it to populate the value of "A" into the Kiln field and if the value of Kiln Set = 12 I need it to populate a value of "B" for Kiln.

I gave it a shot using this recordset code that I coded myself. There are not any syntax errors but its not populating the information I asked for. Any thoughts?

Expand|Select|Wrap|Line Numbers
  1.  Private Sub Kiln_Click()
  2.    Dim dbs As DAO.Database
  3.     Dim rsGen3 As DAO.Recordset
  4.     Dim rsDrumResults As DAO.Recordset
  5.  
  6.     Set dbsGen3 = CurrentDb
  7.     Set rsKilnData = dbsGen3.OpenRecordset("tblKilnData")
  8.     Set rsDrumResults = dbsGen3.OpenRecordset("tblDrumResults")
  9.  
  10.     With rsKilnData
  11.         Do While !Gen3Run = rsDrumResults![Batch Number]
  12.            If ![Kiln Set] = 11 Then
  13.  
  14.                     rsDrumResults!Kiln = "A"
  15.  
  16.                 ElseIf ![Kiln Set] = 12 Then
  17.  
  18.                     rsDrumResults!Kiln = "B"
  19.                 Else
  20.  
  21.             End If
  22.         Loop
  23.         .Close
  24.     End With 'rsKilnData
  25.     dbsGen3.Close
  26. End Sub
  27.  
May 19 '14 #1
7 1537
zmbd
5,501 Expert Mod 4TB
- You talk about two different databases and yet your code only refers to one database file.
- Your loop at 10 never steps thru any records... and I'm not sure what your trying to do there anyway.

- Maybe take a look at this:> Database Normalization and Table Structures. as I feel that there just isn't something right about your database structure.
May 19 '14 #2
devarts
16
1) I'm sorry I didn't explain that I linked the tale called tblKilnData from the other database to the Gen3 database. That is why I did not define in the code, but If I still need to define it, even though its linked, I can do that.

2) I had a feeling that could be the case. I didn't quite know how to go about do that part. I want to find the value of the Batch number that matched the batch number in the Gen 3 database. Once it found it, I would like to pull information from that record. But I wasn't sure how to exactly go about that.

3) And all the databases that I work with are already created except for the Gen 3 database. So any structural issues I will have to just live with.
May 20 '14 #3
zmbd
5,501 Expert Mod 4TB
devarts

Sometimes I'm a little slow at things... blame the Chemist in me (^_^)

Just to make sure that I properly understand how things are going:

External Database with a Linked table to the current and we need to match a field in that table:
[tblKilnData]![Kiln]

In the current database (GEN3) we have table and form and we want to relate the information between the [tblKilnData]![Kiln] and this current information crossrefenced by:
[tblDrumResults]![Batch_Number]

so that
[tblDrumResults]![Batch_Number] = 11
then
[tblDrumResults]![Kiln_xref] = "A"

so that
[tblDrumResults]![Batch_Number] = 12
then
[tblDrumResults]![Kiln_xref] = "B"

so that you can then pull/update (etc) information from [tblKilnData]

Is that correct?

If so then with a query, a calculated field, and join I think we can get what you need without any VBA.
May 20 '14 #4
devarts
16
Not exactly... everything is correct until you get to "so that
[tblDrumResults]![Batch_Number] = 11
then
[tblDrumResults]![Kiln_xref] = "A... etc"

Just to point out the Batch Number in tblKilnData is called Gen3Run. I am not sure why but thats the naming convention that was put for that field. So that may help a little.

But essentially I would like to do this:

Form with txtBatchNumber --> enter a number --> 200
Where in tblKilnData!Gen3Run does the field = 200
When it is found... under the same record... what value is Kiln Set?
Say the code was able to find the record that matched the batch number of 200 and it correlated the Kiln Set value to be 11

Now that we now its a 11, I want it to return a value for tblDrumResults!Kiln of A for record 200.

Does that make sense or did I just make things more complicated?
May 20 '14 #5
twinnyfo
3,653 Expert Mod 2GB
devarts,

I know this post has been hanging out there for a while, but I wonder why you couldn't just use a DLookup on your Kiln Table:

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtBatchNumber_AfterUpdate()
  2.     Me.txtKilnSet = IIf(Nz(DLookup("[KilnSet]", "tblKilnData", _
  3.         "[BatchNumber] = " & Me.txtBatchNumber), 0) = 11, "A", _
  4.         Nz(DLookup("[KilnSet]", "tblKilnData", _
  5.         "[BatchNumber] = " & Me.txtBatchNumber), 0) = 12, "B", "-")
  6. End Sub
I don't know the exact names of your Text Boxes, but this would eliminate the need for a recordset. It also depends on if your Kiln Set is an actual number versus a number in text format.

Let me know if this hepps!
Jun 10 '14 #6
zmbd
5,501 Expert Mod 4TB
Record set vs. the Dlookup would do with number of records and the location of the data which sounds to be in a different type of database/

In anycase, I've been out of the office w/o access to the net for the past few weeks. I had hopped that someone would have jumpped on the cart with us as we rolled into that kiln.

I may be a bit slow in answering things for the next few weeks as I need to get the lab back up to speed. I'm gone and the whole place starts to fray at the ededges...along with my spelling. (^_^)
Jun 11 '14 #7
twinnyfo
3,653 Expert Mod 2GB
Then, modifying the OP's original Code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Kiln_Click()
  2.     Dim dbs As DAO.Database
  3.     Dim rsKilnData As DAO.Recordset
  4.  
  5.     Set dbs = CurrentDb
  6.     Set rsKilnData = dbs.OpenRecordset("tblKilnData")
  7.  
  8.     If Not rstKilnData.EOF Then
  9.         rstKilnData.MoveFirst
  10.         Do While Not rstKilnData.EOF
  11.             If rstKilnData!Gen3Run = Me.txtBatchNumber Then
  12.                 If rstKilnDat("Kiln Set") = 11 Then
  13.                     Me.txtKiln = "A"
  14.                 ElseIf rstKilnDat("Kiln Set") = 12 Then
  15.                     Me.txtKiln = "B"
  16.                 Else
  17.                     Me.txtKiln = ""
  18.                 End If
  19.                 Goto Kiln_Exit
  20.             End If
  21.         Loop
  22.     Else
  23.         Me.txtKiln = ""
  24.         Goto Kiln_Exit
  25.     End If
  26. Kiln_Exit
  27.     rstKilnData.Close
  28.     dbs.Close
  29.     Set rstKilnData = Nothing
  30.     Set dbs = Nothing
  31. End Sub
This code creates a Recordset of tblKilnData, and cycles thorugh the records until it finds the appropriate Batch Number that was entered into the Form Text Field. If no record is found matching those results, then the Kiln Text Box on the Form is set to "".

When this code finds the Batchnumber in the Field Gen3Run, it checks to see what the Kiln Set is. If it matches either 11 or 12, then it sets the Kiln value properly; otherwise, "". Since the recordset found the Batch Number, there is no need to cycle through any remaining records, to the code just exits at that point.

I hope this hepps!
Jun 12 '14 #8

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

Similar topics

2
by: SAN CAZIANO | last post by:
How can I display all the record of a certain field in a combobox after I have connected to a db in mysql ??? thanks a lot -- Alberto
2
by: Steve | last post by:
Does any anyone have a procedure for a query where a calculated field returns the previous record's value in another field. For example: A F A Z F M Z The primary key is in random...
2
by: lovecreatesbeauty | last post by:
Hello experts, When I allocate memory use malloc() and forget to call a corresponding free(), does this allocated memory lose forever after program exits (Can i regard it same as process...
2
by: MLH | last post by:
Fields in MyTable: PostID PostDate RollQtyXfer RollDenomination RollCount37 RollCount23
2
by: john | last post by:
Is there a hotkey in Access that pastes the previous record's value in a field? In Excel it's Ctrl-D. Thanks, john
8
by: ngpbalaji | last post by:
How the Memory will be Allocated for the C programs ...., C static & dynamic variables ? Who will allocate memory for these...? physically where it will be ...? Regards Balaji
5
by: vandanavai | last post by:
Hello, I have problem in setting default value of field. What I want to do is as follows. I have 'Table' with fields 'PurchaseDate' and 'CapitalisationDate'. I want to set dafault value of field...
1
by: sudermatt | last post by:
This one is completely baffling. DB Enviornment: MSSQL database Code Environment: ASP / VBscript (obviously) Problem: data from an nText field disappears from conn.execute(sql) recordset. ...
5
by: antony123 | last post by:
Hai All hard coders , Tell me how to get the value of field in a record in a recordset onject in visual basic using is index rather than the field name.Please help me .
1
by: MLH | last post by:
Put 2 tables in a qbe grid & link 'em so as to list only records in tblA that have related records in tblB. Run the query. HiLite a row. Press delete key. A record is deleted. How can you...
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: 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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.