Database won't refresh with DoCmd.Requery

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
640
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I'm using the Excel Userform on the front end and Access on the back end. So after the Enter button is pressed, the information on the form is entered into the database but the database won't "Refresh All" at the line with "DoCmd.Requery". However, when I place a break at "Unload Me" and step through the next line "DoCmd.Requery", it then refreshes the database. Any help explaining why VBA does this or how to fix this issue would be very helpful. Thank you.

VBA Code:
Private Sub btnEnter_Click()
    Call ConnectDB_Insert
    Unload Me
    DoCmd.Requery
End Sub
VBA Code:
Sub ConnectDB_Insert()
    'Path
    Dim strPath As String
  
    'Provider
    Dim strProv As String
  
    'Connection String
    Dim strConn As String
  
    'Connection
    Dim Conn As New Connection
  
    'RecordSet
    Dim reQry As New Recordset
  
    'SQL Query
    Dim strQry As String
  
    strPath = "C:\Users\Name\OneDrive\Documents\Personnel.accdb"
    strProv = "Microsoft.ACE.OLEDB.12.0;"
    strConn = "Provider=" & strProv & "Data Source=" & strPath
  
    'Connection Open
    Conn.Open strConn
  
    strQry = "INSERT INTO Personnel ([Employee #], [First Name], [Last Name], [Email]) VALUES('" & frmPersonnelEntry.txtEmpNum.Text & "','" & frmPersonnelEntry.txtFN.Text & "','" & frmPersonnelEntry.txtLN.Text & "','" & frmPersonnelEntry.txtEmail.Text & "')"
      
    Conn.Execute strQry
  
    
End Sub
 
Hi @Pookiemeister,
Maybe:
VBA Code:
Private Sub btnEnter_Click()
    Call ConnectDB_Insert
    Application.Wait (Now + TimeValue("00:00:01"))
    DoCmd.Requery
    Unload Me
End Sub
???
 
Upvote 0
Ok. I just read a post that said that DoCmd does not work in Excel. Now I'm wondering if there is a work around?
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top