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

Edit Record on a form using a popup form

72 64KB
Hi
I need to edit a specific record on a main form using a popup form. this is the code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub resetThisForm(strAction As String)
  2.     On Error GoTo ErrorHandler
  3.  
  4.     Dim rst As DAO.Recordset
  5.  
  6.     Select Case strAction
  7.         Case "Swap"
  8.             Set rst = Forms!frmMain.Recordset
  9.  
  10.             With rst
  11.                 .Bookmark = Forms!frmMain.Bookmark
  12.                 .Edit
  13.                     !fkLocationID = Me.txtLocationPK
  14.                 .Update
  15.             End With
  16.  
  17.         Case "Add"
  18.             '...
  19.     End Select
  20.  
  21.     Me.Visible = False
  22.  
  23.  
  24. exitSub:
  25.     Set rst = Nothing
  26.     Exit Sub
  27. ErrorHandler:
  28.     MsgBox "Error No: " & Err.Number & vbNewLine _
  29.          & "Error Details: " & Err.Description & vbNewLine _
  30.          & "Error in Sub: frmMain_TableAdd\resetThisForm"
  31.     Resume exitSub
  32.  
  33. End Sub
I was wondering though if declaring and setting the recordset is needed in this case. Shouldn't I avoid opening another recordset and just do the following, thanks

Expand|Select|Wrap|Line Numbers
  1. Private Sub dresetThisForm(strAction As String)
  2.     On Error GoTo ErrorHandler
  3.  
  4.     Select Case strAction
  5.         Case "Swap"
  6.  
  7.             With Forms!frmMain.Recordset            
  8.                 .Edit
  9.                     !fkLocationID = Me.txtLocationPK
  10.                 .Update
  11.             End With
  12.  
  13.         Case "Add"
  14.             '...
  15.     End Select
  16.  
  17.     Me.Visible = False
  18.  
  19. exitSub:
  20.     Exit Sub
  21. ErrorHandler:
  22.     MsgBox "Error No: " & Err.Number & vbNewLine _
  23.          & "Error Details: " & Err.Description & vbNewLine _
  24.          & "Error in Sub: frmMain_TableAdd\resetThisForm"
  25.     Resume exitSub
  26.  
  27. End Sub
Mar 12 '21 #1

✓ answered by NeoPa

Neruda:
I have decided to edit that record using the main form's recordset instead of a (UPDATE) sql statement.
Good luck with that.
Neruda:
I dont want to directly edit the record on the main form. I have to use a pop up for that.
That's a problem. If the main Form allows updates then I suspect you'll find you sometimes get clashes if you try that. If it doesn't then the Recordset object won't allow it either.
Neruda:
Since there are many ways to update a record in forms I was wondering if the second block of code (above) makes more sense because the first opens yet another recordset.
Well, the first block doesn't open another Recordset. It simply uses an extra (wasted) pointer to the same Recordset. I see little sense in either block if I'm honest but if the second makes more sense then it's only because it doesn't create an extra Recordset object which is merely a pointer to that of the main Form and not materially different in any way.

I can warn you away from such an approach - as I have done twice now - but only you can decide how you wish to continue.

3 1727
NeoPa
32,556 Expert Mod 16PB
Hi Neruda.

I assume this code is within the Form [frmMain]?

It's very difficult to help because your explanation of what the code is doing doesn't have any relation to the code itself. Unfortunately, the code (Both sets) is so full of things that don't make sense that it's hard to read it & even guess what it is you're trying to do.

So, How can I help? Maybe I can state a few facts that will give you some perspective on what it is you're actually doing/thinking about.
  1. Forms have a Recordset object as well as a RecordsetClone object.
  2. The Recordset object is what is used by the Form to manage the data you see on the Form. The current record will already match the data you see on the Form.
  3. The RecordsetClone object is configured the same way as the Recordset - having the same fundamental set of data to work with - but it typically stays at the first record until moved.
  4. Assuming the Form you're working within is actually named [frmMain] as expected, then Forms!frmMain is just a long way of saying Me. That only works for code within the [frmMain] Module though of course.
  5. Using .Edit / .Update directly on a Form's Recordset is almost never necessary & it is prone to causing blocking (Where the data isn't available in one place because it's in use & locked in the other). You should never do it.
  6. There may be a good reason why you might want to try that, but I very much doubt it. This just looks like very confused coding. If you want to set the value in the record then do so via the Control on the Form that's linked to that Field.
  7. In this case it looks even worse than that as it looks like you're actually trying to set the value from itself.
I hope some of this helps & if you have any questions feel free to ask.
Mar 12 '21 #2
Neruda
72 64KB
I assume this code is within the Form [frmMain]?

No,
the code above is in a popup form. It edits a field (fkLocationID) on the main form.
I have decided to edit that record using the main form's recordset instead of a (UPDATE) sql statement. I dont want to directly edit the record on the main form. I have to use a pop up for that. Since there are many ways to update a record in forms I was wondering if the second block of code (above) makes more sense because the first opens yet another recordset .


thanks
Mar 12 '21 #3
NeoPa
32,556 Expert Mod 16PB
Neruda:
I have decided to edit that record using the main form's recordset instead of a (UPDATE) sql statement.
Good luck with that.
Neruda:
I dont want to directly edit the record on the main form. I have to use a pop up for that.
That's a problem. If the main Form allows updates then I suspect you'll find you sometimes get clashes if you try that. If it doesn't then the Recordset object won't allow it either.
Neruda:
Since there are many ways to update a record in forms I was wondering if the second block of code (above) makes more sense because the first opens yet another recordset.
Well, the first block doesn't open another Recordset. It simply uses an extra (wasted) pointer to the same Recordset. I see little sense in either block if I'm honest but if the second makes more sense then it's only because it doesn't create an extra Recordset object which is merely a pointer to that of the main Form and not materially different in any way.

I can warn you away from such an approach - as I have done twice now - but only you can decide how you wish to continue.
Mar 13 '21 #4

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

Similar topics

2
by: vishal | last post by:
hello friends i have one php script which generates html page containing form. what i want is submit this form using php script. pls give me some idea that how can i submit form using php...
4
by: Skully Matjas | last post by:
I am using the following code (created by the wizard) to allow to bring my form to a particular entery. But when I edit the entery (ex: put new information into a blank cell), it puts that record...
4
by: Kevin Myers | last post by:
Hello, Please forgive my reposting of this note with hopefully a more relevant subject line. On an Access 2000 form under Windows 2000 I would like to use a Kodak Image Edit Control to...
6
by: Robin S. | last post by:
Originally I wanted a list box which selects which record is the current one within the same form. Easy enough until Access takes a dump when one is deleted and then someone tries to select it in...
1
by: Richard Coutts | last post by:
I have a Continuous Form where each record has a button that activates another form that simplifies entering values into the record. The activated form has the equivalent of a "Done" button. I'd...
5
by: Lyn | last post by:
Hi, I hope someone can help. I have a main form which mostly fills the Access window. In the bottom half of this form I have a tab control to display various types of data related to the main...
1
by: alex.gruenther | last post by:
I am new to Access and need help creating an edit record form. I've got a table called Player with attributes like name, address, phone, etc. I've created an edit player form with a combo box...
3
by: scripteaze | last post by:
posting to a form with no form name or it's just that i cant find the form name. can anyone explain how to either post to a form with no name or, find the name of the form..here my current output,...
2
by: wassimdaccache | last post by:
Hello Working on access 2007. My database file is made on access2003. I have 2 forms. (categories) and (Productlistsearch). The Productlistsearch form contain a subform called "Products...
2
by: bigukfan | last post by:
I have an application that is used to collect clinical data from hospital patients involved in research. Various forms are used to collect specific data, often blood results. When the users enter...
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
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
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,...

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.