Sub form requery, cache flush, etc etc. (1 Viewer)

oaishm

Registered User.
Local time
Today, 06:17
Joined
Oct 4, 2009
Messages
10
I have a main form that inserts data into a table. There's then a subform that should be re-populated based on the new info just inserted into the table from the main form. To avoid a "XXXX has put the database into a locked state so you can't modify the records" error, I 've split my database up between client and server (Which was very painful for newbies to do). So I linked my client to the server tables, but I don't build out a working table of some sort with the new data, because it seems senseless. Now, the database works fine, but I can't seem to get the subform to update whenever I save data using the main form. The only way the subform updates is by closing the form and opening it again or changing a field on the main form that the sub form is bound to with the parent child link, and then changing the field back to what it was. Here's the code I used, with a tremendous amount of stuff I found on the web to try to coax the form to requery:
Code:
Option Compare Database
 
Private Sub cardnum_AfterUpdate()
Me.Filter = "[Card Number] = """ & cardnum & """"
Me.FilterOn = True
End Sub
Private Sub plu_AfterUpdate()
Dim cn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs As ADODB.Recordset
Dim strSQL As String
Dim RA As Long
Set cmd = New ADODB.Command
Set rs = New ADODB.Recordset
With cmd
    .CommandText = "Select * from MenuItem where PLU='" & plu & "'"
    .CommandType = adCmdUnknown
    .ActiveConnection = CurrentProject.Connection
    Set rs = .Execute
End With
rs.MoveFirst
nme = rs!Description
price = rs!price * 0.85
rs.Close
Set rs = Nothing
Set cmd = Nothing
Set cmd = New ADODB.Command
Set rs = New ADODB.Recordset
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=c:\Documents and Settings\Administrator\My Documents\scrappink.mdb;" & _
        "Mode=ReadWrite;" & _
        "Persist Security Info=False"
cn.Open
With rs
    .Open "CustomerItem", cn, adOpenDynamic, adLockOptimistic, adCmdTable
    .AddNew
    !Item = plu
    ![Item Name] = nme
    !Customer = cardnum
    !price = price
    !quantity = qty
    !Tax = price * qty * 0.0925
    ![Total Amount] = price * qty * 1.0925
    .Update
End With
cn.Close
Set cn = Nothing
DBEngine.Idle dbRefreshCache
DoEvents
DoEvents
Me![CustomerItem subform].Requery
Me.Requery
DoCmd.RunCommand acCmdRefresh
qty = 1
plu = ""
plu.SetFocus
End Sub
Private Sub plu_BeforeUpdate(Cancel As Integer)
Dim cmd As New ADODB.Command
Dim rs As ADODB.Recordset
Dim strSQL As String
Dim RA As Long
Set cmd = New ADODB.Command
Set rs = New ADODB.Recordset
With cmd
    .CommandText = "Select * from MenuItem where PLU='" & plu & "'"
    .CommandType = adCmdUnknown
    .ActiveConnection = CurrentProject.Connection
    Set rs = .Execute
End With
If rs.EOF Then
    MsgBox "This item doesn't exits"
    Cancel = True
End If
rs.Close
Set rs = Nothing
Set cmd = Nothing
End Sub
 

HiTechCoach

Well-known member
Local time
Today, 08:17
Joined
Mar 6, 2006
Messages
4,357
To requery a sub form, I normally use this syntax:

Code:
Me.[subform_control_Name].form.Requery
 
Last edited:

oaishm

Registered User.
Local time
Today, 06:17
Joined
Oct 4, 2009
Messages
10
Alas that's another variation that didn't work:

Me.CustomerItem_subform.Form.Requery

Me!CustomerItem_subform.Form.Requery

Me!CustomerItem_subform.Requery


No clue why soem people us a ! and some a dot. Doesnt' matter, neither of them work.

Also tried this:
http://www.utteraccess.com/forums/showflat.php?Cat=&Number=792317&Main=792187

But as you can see, it didn't work

This person failed as well:
http://objectmix.com/ado-dao-rdo-rds/360578-ado-form-requery.html

I think access just wan't meant to handle it
 

boblarson

Smeghead
Local time
Today, 06:17
Joined
Jan 12, 2001
Messages
32,059
Alas that's another variation that didn't work:

Me.CustomerItem_subform.Form.Requery

Me!CustomerItem_subform.Form.Requery

Me!CustomerItem_subform.Requery


No clue why soem people us a ! and some a dot. Doesnt' matter, neither of them work.

First of all it is not Me! it shoudl be Me. (dot) A bang generally is used for collections and a dot for properties and methods. Now there's a whole lot of discussion around all of that but we can dispense with that.

Second, you reference the subform control name (not the subform name), so if the control on the main form which houses your subform is not named CustomerItem_subform then you need to use the right name.

See here -



So, it is

Me.YourSubformControlName.Form.Requery (replacing the YourSubformControlName with the actual name of the subform control and not the subform name).
 

oaishm

Registered User.
Local time
Today, 06:17
Joined
Oct 4, 2009
Messages
10
Here's something else that doesn't work, resetting the record source and requerying:

Me.CustomerItem_subform.Form.RecordSource = "Select * from CustomerItem where Customer ='" & [cardnum] & "'"

Me.CustomerItem_subform.Form.Requery
 

boblarson

Smeghead
Local time
Today, 06:17
Joined
Jan 12, 2001
Messages
32,059
Here's something else that doesn't work, resetting the record source and requerying:

Me.CustomerItem_subform.Form.RecordSource = "Select * from CustomerItem where Customer ='" & [cardnum] & "'"

Also, where is cardnum from? Is it from the form? Is it a number?

If on the form and a number it would be

Me.CustomerItem_subform.Form.RecordSource = "Select * from CustomerItem where Customer =" & Me.cardnum

I think it might be quicker to figure this out if you uploaded your database.
 

oaishm

Registered User.
Local time
Today, 06:17
Joined
Oct 4, 2009
Messages
10
You know, I thought it should be a dot, not a bang, but as you can see on the web, people shorten Form!Parentname. to Me!. Anyway, it's easy to see both.

Here's my properties screen capture:


Maybe its because Microsoft defaults both the source and control name to the same exact name and I didnt' change it and the redundancy confuses people. If that's the case, I dont' have really kind words to say about access
 

boblarson

Smeghead
Local time
Today, 06:17
Joined
Jan 12, 2001
Messages
32,059
Doesn't look like there's an UNDERSCORE (_) in the name. If it isn't there, it isn't used. So you would need to use brackets and DON'T use the underscore if it isn't in the actual name:

Me.[CustomerItem subform].Form.RecordSource = "Select * from CustomerItem where Customer =" & Me.cardnum
 

oaishm

Registered User.
Local time
Today, 06:17
Joined
Oct 4, 2009
Messages
10
http://www.scrapbookingsuppliesrus.com/images/product1/scrappink.zip

My database is too big for upload, so I added it as a link.

I originally didn't want to change the record source (which by the way worked) I just wanted to requery. I changed the record source to force it to refresh. Two things get the subform to refresh. Go into debug mode by setting break points. Changing the main form record that the sub form is tied to. Trying the refresh cache method in my prior post didn't work.

Thank you so much for taking the time to help me. I appreciate it immensely as I"ve been beating my head on this for a week
 

boblarson

Smeghead
Local time
Today, 06:17
Joined
Jan 12, 2001
Messages
32,059
Yep, just as I thought, you were adding an underscore instead of using brackets. The code should use

Me.[CustomerItem subform].Form.RecordSource

instead of

Me.CustomerItem_subform.Form.RecordSource
 

oaishm

Registered User.
Local time
Today, 06:17
Joined
Oct 4, 2009
Messages
10
You know. When I first looked at that underscore, I thought the same thing you did. Then I saw this



And I just figured that Microsoft is different than every other language I've come across in that they purposely change spaces to underscore. So I did the same thing.

This is a weird language. Anyway, I pray you can solve my problem.
 

oaishm

Registered User.
Local time
Today, 06:17
Joined
Oct 4, 2009
Messages
10
Oh yes, so to be clear,
Code:
DBEngine.Idle dbRefreshCache
DoEvents
DoEvents
Me.[CustomerItem subform].Form.Requery
Me.Requery
DoCmd.RunCommand acCmdRefresh
qty = 1
plu = ""
plu.SetFocus
didn't work and I wonder if setting the record source won't work either.

alas. It doesn't
 

Users who are viewing this thread

Top Bottom