I'm trying to setup reminders based on tasks added from a Table called "Tasks" Here is the code I'm using but something isn't right as it keeps giving me issues with the following line:
intStore = DCount("[TaskName]", "[Status]", "[DueDate] <=Now() AND [Complete] =0")
When the code runs I get the error:
Microsoft Access database engine cannot find the input table or query
for 'Status' Make sure it exists and is spelled correctly.
In my table I have fields for Task Name, Status, and Due Date so I'm not exactly sure why this is coming up.
Below is the entire line of code:
Private Sub Form_Load()
'On Load of the switchboard check Jobs table for any uncompleted jobs
Dim intStore As Integer
intStore = DCount("[Priority]", "[Tasks]", "[DueDate] <=Now() AND [PercentComplete] <=0")
If intStore = 0 Then
Exit Sub
Else
If MsgBox("There are " & intStore & " uncompleted jobs" & _
vbCrLf & vbCrLf & "Would you like to see these now?", _
vbYesNo, "You Have Uncomplete Jobs...") = vbYes Then
DoCmd.Minimize
DoCmd.OpenForm "Tasks", acNormal
Else
Exit Sub
End If
End If
End Sub
You can only perform a DCount on one field (primary key is best if you are just doing a general count on the table). You have entered "[Status]" where Access is expecting a table or query name to be used as the source of the [TaskName] field.
See here for more information.
Judging by your other code example I expect that your code needs to be:
intStore = DCount("[TaskName]", "[Tasks]", "[DueDate] <=Now() AND [Complete] =0")
Related
I have inherited and MS Access application. There are many issues that could be changed within the application but unfortunately it was rushed to production and major redesign changes cannot be made.
I have split and given FEs to 6 different users. for the most part there does not seem to be many issues with this, however some users are getting the error "Could not update; currently locked" intermittently when they create a new record on one of the forms and enter into a subform to insert information into it. The main form contains a customers details and the subform contains information on the product that they have.
Optimistic locking being used throughout the application and this doesn't seem to be occurring because two users are updating a single record, as they will basically never being looking at the same records.
I think that the issue may be code that is being used to generate that customer ID. The form where the error occurs is (1_1)Customer Subform. There is a subform within that subform called (1_1_1)Product Subform. These are linked by a PID, which is present in each subform. When the mouse is clicked within the product subform, the application hangs for a few seconds before giving the error "Could not update; currently locked".
There is a button on the form that does the following:
Private Sub NewCustomerRecord_Click()
DoCmd.Close acForm, "1Main_IPCOR"
DoCmd.OpenForm "1Main_IPCOR", acNormal, "", "", , acNormal
Forms![1Main_IPCOR]![1IPCOR_Sform]![(1_1)Customer Subform].SetFocus
DoCmd.GoToRecord , , acNewRec
Forms![1Main_IPCOR]![1IPCOR_Sform]![CREATED_DATE] = Now()
Forms![1Main_IPCOR]![1IPCOR_Sform]![P_ID] = NewP_ID()
Forms![1Main_IPCOR]![1IPCOR_Sform].Form.Refresh
Exit_New_record_Click:
Exit Sub
Err_New_record_Click:
MsgBox Err.Description
Resume Exit_New_record_Click
End Sub
Private Function NewP_ID() As String
Dim strTemplate As String
strTemplate = Replace("CUSXX", "XX", Right(Year(Date), 2))
NewP_ID = Nz(DMax(Expr:="Right([P_ID], 5)", _
Domain:="[(1_1)_Customer]", _
Criteria:="[P_ID] Like '" & strTemplate & "*'"), "0")
NewP_ID = strTemplate & Format(Val(NewP_ID) + 1, "00000")
'Exit function now after successful incrementing or after error message
Exit_P_ID:
Exit Function
'If an error occurred, display a message, then go to Exit statement
P_ID_Err:
MsgBox "Error " & Err & ": " & Error$
Resume Exit_P_ID
End Function
What the function is doing is closing the main form and reopening it with a new ID so a new customer can be added.
Is there anything within the method that may be causing the record to be locked, and never unlocked?
Thanks!
I have a form control (address) that uses Dlookup to call info from a table "database" but the form is bound to table "Tracker". The dlookup is based on another control on the same form - "Name" I need the form to record this dlookup control, along with other controls that are bound to "tracker" as new recordto the table "tracker."
My failed attempts:
Using the default value property to assign the recalled data from the dlookup to another text box which would be bound to "tracker" This simply does not work for some reason. Perhaps I am missing something that tells this control "Address" to update upon selecting the correct "name?"
Code:
Private Sub SubmitReferral_Click()
On Error GoTo Err_SubmitReferral_Click
DoCmd.GoToRecord , , acNewRec
Exit_SubmitReferral_Click:
Exit Sub
Err_SubmitReferral_Click:
MsgBox Err.Description
Resume Exit_SubmitReferral_Click
End Sub
I also tried this - to assign the data - but the data from the dlookup in control "Address1" is not transferring/copying to control "Address2"
Private Sub Combo276_OnUpdate()
OnUpdate ([Address2].Value = [Address1].Value)
End Sub
Help or suggestions?
PS - I have tried to Edit per request to be as specific as possible, and to follow proper board etiquette.
Still unsure of your field names, etc., but the following is an example you can modify. Change 'tblEmployee' to 'database'.
I must state that if you are just starting out with developing in Access (or VBA) that you should never use names that are reserved words, or that can be misleading. Your table named 'database' is ok if named 'tblDatabase'.
Option Compare Database
option Explicit
Private Sub cmdInsert_Click()
Dim strSQL As String
Dim i As Integer
Debug.Print "cmdInsert; "
i = MsgBox("Do you want to add 1 row for Employee ID: " & Me.EmpID & " to table 'tracker'?", vbYesNo, "Confirm Add")
If i = vbNo Then
Exit Sub
End If
DoCmd.SetWarnings True
strSQL = "INSERT INTO tracker ( FirstName, LastName, Add1, City, St, Zip ) " & _
"SELECT tblEmployee.FirstName, tblEmployee.LastName, tblEmployee.Add1, tblEmployee.City, tblEmployee.St, tblEmployee.Zip " & _
"FROM tblEmployee " & _
"WHERE (((tblEmployee.EmpID)=" & Me.EmpID & "));"
DoCmd.RunSQL strSQL
End Sub
Thanks for the help - I solved my concern by hiding the fields that contain the dlookup, and putting code behind a button that copies the information to fields that are bound and therefore will record to the table "tracker"
I have an error message on a form that checks for an existing SSN on the BeforeUpdate event of a text box. If it already exists in the database, the user is given a message box to this effect, and has the option to go to the existing record. I'm using this example code here. My code is below.
Private Sub txtSocialSecurityNumber_BeforeUpdate(Cancel As Integer)
'check for existing SSN
Dim SSN As String
Dim strLinkCriteria As String
Dim rsc As Recordset
Set rsc = Me.RecordsetClone
SSN = Me.txtSocialSecurityNumber.Value
strLinkCriteria = "[SocialSecurityNumber] = " & "'" & SSN & "'"
'look for duplicates
If DCount("SocialSecurityNumber", "Person", LinkCriteria) > 0 Then
'Undo duplicate entry
Me.Undo
'error message
intResponse = MsgBox("Social Security Number " & SSN & " already exists in database." & _
vbCrLf & vbCrLf & "Would you like to view the record?", vbYesNo, "Duplicate SSN")
If intResponse = vbYes Then
'go to record
rsc.FindFirst strLinkCriteria
Me.Bookmark = rsc.Bookmark
ElseIf intResponse = vbNo Then
Exit Sub
End If
End If
Set rsc = Nothing
End Sub
According to this code, and several other examples I have looked up, it seems like I'm doing everything right, but I must not be because when I try to run the code and go to the existing record, I get the error "Run-time error '424': Object Required". When I debug, the row rst.FindFirst strLinkCriteria is highlighted, and hovering over it gives me the text strLinkCriteria = "[SocialSecurityNumber] = '123456789'" (123456789 is a known sample SSN in my database). Thank you to Sergey S. for pointing out the spelling error that fixed this section.
When I tell the message box to go to the record with the existing SSN, it gives me Run-time error '3021': No current record. Debug highlights the line Me.Bookmark = rsc.Bookmark with the message rsc.Bookmark = <No current record.>. So it sounds like I'm not assigning the bookmark correctly.
I've never used bookmarks before, so I'm not really sure what I'm doing wrong here. Any help would be appreciated.
You declared rsc, but used rst.
Change your code to
rsc.FindFirst strLinkCriteria
And I'd recommend always use Option Explicit in every module (default can be changed on options), otherwise you'll face with such kind strange errors. With this option the typo would be found by compiller, not at runtime.
I recently created a database for annual QC checks. I am having trouble creating a front page to view all the information and filter the data using fields as hyperlinks.
Overall setup:
ending if F: form
ending in Q: query
ending in T: table
MapF contains: RegionF(in empty cell), FacilityF(in subform: contain_facility).
I am trying to click on the regionID(autogenerated primary key) and have faciltyF filter the data to only show the associated facilities. They are related in a 1 to many relationship, as in one region can have multiple facilities.
VBA Code:
Private Sub IDregion_Click()
MsgBox "[region] = '" & Me.IDregion & "'"
DoCmd.BrowseTo acBrowseToForm, "facilityF", MapF.contain_facility, "[region] = '" & Me.IDregion & "'", , acFormReadOnly
End Sub
When I click the link on MapF, I get the popup saying [region]='1' after clicking ok, I get the error message:
run-time error'424': object required
Any help you could offer would be great.
As per the information found here, the PathtoSubformControl parameter is a string. So your code should look more like this:
Private Sub IDregion_Click()
DoCmd.BrowseTo acBrowseToForm, "facilityF", "MapF.contain_facility", "[region] = " & Me.IDregion , , acFormReadOnly
End Sub
I was recently given the task of creating a form that will autofill with the information from a table. The information the form autofills is selected using a primary key called ModID. I have a combo box that has a List of the ModIDs that are listed as Active.
SELECT ModID
FROM P_Review
WHERE Status = "Active"
Simple enough. I then have VBA code running on the event After Update. So after the value for the combo box is select or changed it will run this VBA code.
Option Compare Database
Option Explicit
Private Sub selectModID_AfterUpdate()
'Find the record that matches the control.
On Error GoTo ProcError
Dim rs As Object
Set rs = Me.RecordsetClone
With rs
.FindFirst "ModID=" & Me.selectModID
If Not .NoMatch Then
Me.Bookmark = .Bookmark
Else
DoCmd.RunCommand acCmdRecordsGoToNew
Me!localModID = Me.selectModID.Column(0)
End If
End With
ExitProc:
Exit Sub
ProcError:
MsgBox "Error: " & Err.Number & ". " & Err.Description
Resume ExitProc
End Sub
The code runs fine (I get no errors when I debug or run).
Now for the access text box. I would like to populate certain fields based off the variable localModID. I have a dlookup in a text box to find the information in the table P_Review.
=DLookUp("Threshold","P_Review","ModID =" & [localModID])
So the DlookUp should find the value for the column threshold, in the table P_Review, where the ModID in P_Review equals the localModID set in the VBA code. But when I go to form view and select a ModID I get the Error 3070: The Microsoft Access database engine does not recognize as a valid field name or expression. I did copy this code from another database we are already using but it fails in this new instance.
Private Sub ModID_AfterUpdate()
Dim rs As Object
Set rs = Me.RecordsetClone
With rs
.FindFirst "ModID='" & Me.ModID & "'"
If Not .NoMatch Then
Me.Bookmark = .Bookmark
Else
DoCmd.GoToRecord , , acNewRec
Me!ModID = Me.ModID
End If
End With
End Sub
This is the answer to question. I used this code to auto update.
Try
Forms!<whatever_this_form_name_is>![localModID]
in your DLOOKUP