I have two forms PROJECT_VIEW and PROJECT_COMPANY_VIEW. The relationship between these forms is PROJECT_VIEW has a list box populated with companies. Double clicking one of these companies (see code below) will direct you to PROJECT_COMPANY_VIEW.
The issue I am having is: the companyFilter is not being updated on PROJECT_COMPANY_VIEW. As you can see, I am passing it through DoCmd.OpenForm. All of the values that appear in MsgBox are correct, including the COMPANY_ID filter. One thing to note, there are values of a company appearing in PROJECT_COMPANY_VIEW, just not the company I need.
I have tried Clearing All Filters, updating PROJECT_COMPANY_VIEW's record source, deleting the filter in PROJECT_COMPANY_VIEW then closing the form and navigating to it again.
Private Sub ProjectTenderList_DblClick(Cancel As Integer)
Dim tenderID As Integer
Dim companyID As Integer
Dim companyFilter As String
tenderID = ProjectTenderList.Column(0)
MsgBox tenderID
companyID = ProjectTenderList.Column(1)
MsgBox companyID
companyFilter = "COMPANY_ID = " & companyID
MsgBox companyFilter
DoCmd.OpenForm "PROJECT_COMPANY_VIEW", , companyFilter, , , , tenderID
End Sub
Thank you for your time.
Filter criteria is in the wrong argument, needs to be the WHERE CONDITION. Move it over one comma position.
DoCmd.OpenForm "PROJECT_COMPANY_VIEW", , , companyFilter, , , tenderID
Related
I have a form with two combo boxes, one Wards the other room number. Wards are medical units, while the rooms are room numbers (like GMU-01).
I'm trying to limit the room names based on the wards value, ie list all the bed numbers for a particular unit.
SELECT DISTINCT [TblWards].[Wards] FROM TblWards ORDER BY [TblWards].[Wards];
The row source from the Wards combo box (First box)
Private Sub Wards_AfterUpdate()
Dim txt As String
txt = "SELECT TblWards.Room FROM TblWards WHERE (TblWards.Wards)= '" &
Me.Wards.Column(0) & "' ORDER BY TblWards.Room;"
Me.RoomN.RowSource = txt
End Sub
SELECT [TblWards].[Room] FROM TblWards WHERE ((([TblWards].[Wards])=AMU));
The row source from the second combo box RoomN
I get an error when I attempt to choose a value from the Wards combo box. If I line out the afterupdate code, I can choose a value. The error is unexpected error, access needs to shut down.
Then, I get an error if I attempt to select a value from the second combobox. asking for the AMU parameter.
I inherited this code and trying to determine how to go about it, rewrite or try to salvage it.
from what I understand from your message, you can try this:
Private Sub cboWard_AfterUpdate()
Dim strSQL As String
strSQL = "SELECT * FROM tblRooms WHERE rWardID = " & Me.cboWard
Me.cboRoom.RowSource = strSQL
End Sub
Try Following-
Clear ControlSource and RowSorce Property of comboBox 'RoomN' Manually.
Try following code in AfterEvent of 'Wards' comboBox
Private Sub Wards_AfterUpdate()
Dim txt As String
txt = "SELECT Room FROM TblWards WHERE [Wards] = '" & Me.Wards.Value & "' ORDER BY Room;"
Me.RoomN.RowSource = txt
End Sub
I have read and read posts that seem to answer my exact question, but nothing I try works. I'm clearly missing something simple. I have a report showing employee overtime. I want the user to be able to click a hyperlink or button for the overtime entry and open a form to edit the entry.
The following code pulls up a parameter input box for Overtime_ID. Also entering the Overtime_ID manually will open the correct form, but it seems to default to the first record in the underlying table.
Private Sub Overtime_ID_Click()
Dim recordID As Integer
recordID = Me.Overtime_ID
DoCmd.OpenForm "frmEditOvertime",,, "Overtime_ID = " & recordID, acFormEdit
End Sub
Record Source for frmEnterOvertime is a table - Overtime Awards.
The columns in that table are:
Overtime ID (AutoNumber and PK)
Entry Date
Overtime Date
Squad List (short text)
Overtime Hours(number)
Supervisor(number)
Comment(short text)
Mandatory (Yes/No)
Correction (Yes/No)
Officer ID(Number)
Because Overtime ID has a space in its name, simply bracket [] or use backticks in OpenForm call. You cannot simply use underscore as replacement as that changes the column identifier.
DoCmd.OpenForm "frmEditOvertime",,, "[Overtime ID] = " & recordID, acFormEdit
DoCmd.OpenForm "frmEditOvertime",,, "`Overtime ID` = " & recordID, acFormEdit
And do note the where argument can use any compliant SQL WHERE condition.
EDIT: I guess I do not understand how the stuff for the subform is being used/retrieved based on the frmInvoice that is called. The frmInvoice uses tblInvoice which is an archive table or one that doesn't get a record till the invoice is saved. Yet the subform loads (before i started mucking with all this) with all the right information?
Sure enough editing the frmInvoice showed the Filter field to be that where clause. So I guess I do not follow how the subform is getting the right groupID (in the original example) and presenting the right information from those queries based on this work flow.
I am trying to fix a database for someone, I am not too familiar with access vba. So I am confused why the following isn't working. I have a form, that when a button is clicked. It opens another form with a subform. The queries I changed a bit to include another field to key on. So I have this script here:
Private Sub GroupAddress_DblClick(Cancel As Integer)
Dim intGroup As Integer
Dim stDocName As String
Dim stLinkCriteria As String
intGroup = Me![GroupID]
strGroupName = Me![Group]
stDocName = "frmInvoice"
stLinkCriteria = "[GroupName]='" & strGroupName & "'"
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub
The line that sets the GroupName, Does not work, wants me to enter parameter GroupName. But if I replace it with this line:
stLinkCriteria = "[GroupID]= " & intGroup
It works fine! No question to ask
The subform record source is here:
SELECT qryInvoiceSubformSHANE.Provider, qryInvoiceSubformSHANE.GroupID, qryInvoiceSubformSHANE.Dues, qryInvoiceSubformSHANE.Adjustment, qryInvoiceSubformSHANE.AdjustmentDescription, qryInvoiceSubformSHANE.GroupName FROM qryInvoiceSubformSHANE;
The query that is from (qryInvoiceSubformSHANE) is here:
SELECT tblProvider!ProviderLName & ", " & tblProvider!Designation & ", " & tblProvider!ProviderFName AS Provider, tblProvider.GroupID, tblDesignation.Dues, tblProvider.Adjustment, tblProvider.AdjustmentDescription, tblProvider.GroupName
FROM tblGroup INNER JOIN (tblDesignation INNER JOIN tblProvider ON tblDesignation.DesignationID = tblProvider.DesignationID) ON tblGroup.GroupID = tblProvider.GroupID;
so not sure why this just doesn't work with the GroupName as the where clause?
I have a database that monitors staff leave and training, every 8 weeks a group will gather and then do training, what i am after is a way to rather than individually assign each member a training event id rather open the event and select the participants, from here each staff member will have this specific training logged against them
So far i have each staff recognised by ID and each training by GID but am having trouble entering this training event in against all IDs?
This BULK INSERT could be probably done by using an Unbound Form. The minimal controls would be one Listbox, ComboBox, a TextBox and a Button.
ListBox (staffList), which should be allowed to select multiple items; will obtain its RowSource from the Staff table, something like
SELECT
staffID,
staffName
FROM
staffTable;
The properties would be Bound Column : 1, Column Count : 2, Column Widths : 0cm;2.542cm
The ComboBox (eventCombo), will obtain its RowSource from the Event table, something like
SELECT
eventID,
eventName
FROM
eventTable;
The properties would be Bound Column : 1, Column Count : 2, Column Widths : 0cm;2.542cm
Then the TextBox (dateTxt) would just have a Date control (for the date of the event).
The code behind the Button (addEventBtn) click would simply be,
Private Sub addEventBtn_Click()
Dim varItem As Variant
If Me.staffList.ListIndex = -1 Then
MsgBox "No Staff selected. You have to select at least one staff before you can proceed !", vbCritical
Me.dateTxt.SetFocus
Exit Sub
End If
If Me.eventCombo.ListIndex = -1 Then
MsgBox "No Event selected. You have to select at least one staff before you can proceed !", vbCritical
Me.dateTxt.SetFocus
Exit Sub
End If
If IsNull(Me.dateTxt) Then
MsgBox "No Date selected. You have to select Date before you can proceed !", vbCritical
Me.dateTxt.SetFocus
Exit Sub
End If
For Each varItem In Me.staffList.ItemsSelected
CurrentDB.Execute "INSERT INTO tbl_EventList (eventID_FK, staffID_FK, eventDate) VALUES (" & _
Me.eventCombo & ", " & Me.staffList.ItemData(varItem) & ", " & Format(Me.dateTxt, "\#mm\/dd\/yyyy\#") & ")"
Next
End Sub
This should work out. Please change it according to your design ! If you have any questions please add them to comments.
Here's my question: i have a subform inside a main form. The main form contains the customer number, and the subform contains the order for that customer. So one customer may have multiple orders. I want to create a buttom which when clicked moves to the next order for that customer. I have no issue doing this with the code:
Private Sub next_comp_Click()
[Forms]![Customer]![Order Subform].SetFocus
DoCmd.GoToRecord , , acNext
end sub
where I have issues is when I get to the last order for that customer. I will like it to loop back to the first order. To do this i used this code:
Private sub next_comp_click()
[Forms]![Customer]![Compressor Subform].SetFocus
Dim dbcustomer As Database
Dim rstorder As Recordset
Set dbcustomer = CurrentDb
Set rstorder= dbcustomer.OpenRecordset("orders", dbOpenSnapshot)
With rstEmployees
If .AbsolutePosition = - 1 Then
MsgBox (.RecordCount)
'DoCmd.GoToRecord , , acFirst
Else
DoCmd.GoToRecord , , acNext
End If
End With
end sub
I used the MsgBox function to kind of debug to figure what record I am on (ultimately I want it to loop back to the first record as shown in the commented out code), but for some reason, it tells me i am always on the first record, i.e. it tells me the RecordCount is 1. This is not supposed to be so because most of the records I am working with have multiple orders. If I change the condition to something like If .AbsolutePosition = 3, it moves the records to the next until i get to the last or empty record and if i click next from there, it gives me the run-time error '2105' you cannot go to the specified record.
I think the issue is the .AbsolutePositon property is not looking at the right form or table, but any answers will be much appreciated.
Thank you in advance.
You do not even need that recordset stuff if your forms are bounded. Just use the following code in the button:
Private sub next_comp_click()
[Forms]![Customer]![Order Subform].SetFocus
If [Forms]![Customer]![Order Subform].Form.CurrentRecord >= [Forms]![Customer]![Order Subform].Form.Recordset.RecordCount Then
DoCmd.GoToRecord , , acFirst
Else
DoCmd.GoToRecord , , acNext
End If
End sub
I built an access database to replicate this just to make sure the code was exact. You should be able to copy and paste this and it will work.
This is what I do to loop to the First record after hitting the last record. Put it in VBA. Just do the reverse if using a previous button.
If Me.CurrentRecord = Me.Recordset.RecordCount Then
DoCmd.GoToRecord , , acFirst
Else
DoCmd.GoToRecord , , acNext
End If