When I paste a value into a combo box, it is not displayed when I paste it on load. Although when inserting a value without passing an argument into the form, everything works. How to fix it?
The first picture shows the problem itself. The second shows that everything will work without passing an argument to the form! And in the drop-down list itself, everything is displayed
' Populating a list of values
If Not Me!PostField.RowSource = "" Then Me!PostField.RowSource = ""
Me!PostField.ColumnCount = 2
Me!PostField.ColumnWidths = "0; 25"
Set QueryRecordset = CurrentDb.OpenRecordset("SELECT tblPost.PostCode, tblPost.PostName FROM tblPost;")
Do Until QueryRecordset.EOF
Me!PostField.RowSource = Me!PostField.RowSource & QueryRecordset("PostCode").Value & ";" & QueryRecordset("PostName").Value & ";"
QueryRecordset.MoveNext
Loop
QueryRecordset.Close
' Inserting user data
QueryObj = CurrentDb.QueryDefs("qrsCurrentEmployeeInfo")
QueryObj![EmployeeCode] = CInt(Me.OpenArgs)
Set QueryRecordset = QueryObj.OpenRecordset
Do Until QueryRecordset.EOF
Me!Title.Caption = QueryRecordset("LastName").Value & " " & QueryRecordset("FirstName").Value & " " & QueryRecordset("MiddleName").Value & " (Ðåäàêòèðîâàíèå)"
Me!LastNameField.Value = QueryRecordset("LastName").Value
Me!FirstNameField.Value = QueryRecordset("FirstName").Value
Me!MiddleNameField.Value = QueryRecordset("MiddleName").Value
Me!SexField.Value = QueryRecordset("Pol").Value
Me!IndividualTaxNumberField.Value = QueryRecordset("InduvialNumber").Value
Me!SalaryField.Value = QueryRecordset("Salary").Value
Me!CompanyField.Value = QueryRecordset("CompanyCode").Value
Me!LegalAddressField.Value = QueryRecordset("LegalAddress").Value
Me!ActualAddressField.Value = QueryRecordset("ActualAddress").Value
Me!PhoneField.Value = QueryRecordset("Phone").Value
Me.MailField.Value = QueryRecordset("[E-Mail]").Value
Me!PostField.Value = QueryRecordset("EmployeePost").Value
QueryRecordset.MoveNext
Loop
Related
I have an Access database that opens multiple instances of 2 reports. The quantity depends on how many student registrations is captured per training run. This may be up to 25, meaning that when the user click on the "Print Documents" button, 25 instances of the 2 reports are opened. The first report is a student registration form, and the second is a indemnity form. Both these forms has certain data on them, like the personal details.
Opening the multiple reports is no issue. The first report is opened with the below code:
Z = 1
While Not Rst3.EOF
Set rpt(Z) = New Report_Rpt_StudentReg
rpt(Z).Visible = True
rpt(Z).Caption = "Student Registation " & Rst3.StudentID
'Append it to the collection.
clnClient.Add Item:=rpt(Z), Key:=CStr(rpt(Z).hwnd)
Rst3.MoveNext
Z = Z + 1
Wend
In the report Rpt_StudentReg On Load, there are code running to with SQL statements to retrieve all the data and fill the fields on the report. The second report (Waiver) is opened from within the first report with similar code below:
Set rptWaiver(Z) = New Report_Rpt_Indemnity
rptWaiver(Z).Visible = True
rptWaiver(Z).Caption = "Indemnity " & Rst3.StudentID
'Append it to our collection.
clnClient.Add Item:=rptWaiver(Z), Key:=CStr(rptWaiver(Z).hwnd)
My issue is none of the data is dispalyed on any of the reports.
If I run a single instance, everything is fine and the relevant data is displayed.
Your assistance is appreciated.
Thanks
Deon
I am opening multiple instances with no issues. In the report's On Load Event, there is code running each time the report is opened. I use SQL to retrieve the data from the tables. Debugging the code, retrieves the correct data, but the data is not on the report when it is opened. The On Load event code as follows:
Private Sub Report_Load()
Set Dbs = CurrentDb: Set Dbs1 = CurrentDb
Select Case Mode
Case "WithData"
If MyMode = "Certification" Then
SQL1 = "SELECT StudentID FROM Tbl_Certification WHERE CertNumber = " & Rst3!CertNumber & ";"
Set Rst1 = Dbs1.OpenRecordset(SQL1)
SQL = "SELECT * FROM Tbl_StudentReg WHERE IDNumber = " & Rst1!StudentID & ";"
Set Rst = Dbs.OpenRecordset(SQL)
Rst1.Close
Else
SQL = "SELECT * FROM Tbl_StudentReg WHERE IDNumber = " & Forms!Frm_StudentReg_Edit.IDNumber & ";"
Set Rst = Dbs.OpenRecordset(SQL)
End If
Set Rst = Dbs.OpenRecordset(SQL)
Me.FirstName = Rst!FirstName
Surname = Rst!Surname
PrevSurname = Rst!PrevSurname
IDNumber = Rst!IDNumber
BirthDate = Rst!BirthDate
AltIDNumber = Rst!AltIDNumber
AltIDType1 = Rst!AltIDType
'-------------------
SQL1 = "SELECT * FROM Tbl_AltID WHERE AltID = " & Rst!AltIDType & ";"
Set Rst1 = Dbs1.OpenRecordset(SQL1)
AltIDTypeDescr1 = Rst1!AltIDDescr
'-----------------------------
Nationality1 = Rst!Nationality
SQL1 = "SELECT * FROM Tbl_Nationality WHERE NationalityNo = " & Rst!Nationality & ";"
Set Rst1 = Dbs1.OpenRecordset(SQL1)
NationalityDescr1 = Rst1!NationalityDescr
'-------------------------------
When the reports are opened for preview, there is no data in the reports. They are all blank.
I am trying to have a way to let the user click multiple checkboxes and lists, to filter a subform. When I try to use an AND statement, I get an error: Run-time rror '13': Type mismatch. I put an arrow to the line in question. Is an And statement not valid syntax for filtering this way?
Private Sub SearchB_Click()
If Me![CoreCB] = True Then
Me.Query1SF.Form.Filter = " IsDate([Core RS]) = True"
Me.Query1SF.Form.FilterOn = True
ElseIf Me![SiteCB] = True Then
Me.Query1SF.Form.Filter = " IsDate([Site RS]) = True"
Me.Query1SF.Form.FilterOn = True
If Not IsNull(SiteCombo.Value) Then
--> Me.Query1SF.Form.Filter = "[Location] = '" & Me.[SiteCombo].Value & "'" And " IsDate([Site RS]) = True" '!! THIS DOESN'T WORK
Me.Query1SF.Form.FilterOn = True
End If
ElseIf Me![SecurityCB] = True Then
Me.Query1SF.Form.Filter = " IsDate([Security]) = True"
Me.Query1SF.Form.FilterOn = True
End If
End Sub
String expression for form filter seems incorrect. Use below line
Me.Query1SF.Form.Filter = "[Location]='" & Me.[SiteCombo].Value & "' And IsDate([Site RS])=True"
I'm using VBA for Access. I have some forms that I want filter.
With the follow code:
a = "ID =" & idwanted
Form_Form1.Form.Filter = a
Form_Form1.Form.FilterOn = True
It works nice, the form is correctly filtred. But I need to filter by 2 fields, something like that:
a = "ID =" & idwanted
b = "Name =" & namewanted
Form_Form1.Form.Filter = a And b
Form_Form1.Form.FilterOn = True
But it give me a error (non match types), but all the fields and variables (a & b) are integer.
(If I do only with b, it filter it correctly.)
Thanks for read me!
You can just make sure you use the right data type literal. Also you need to concatenate the two conditions. Finally Name is a reserved word, so you need to enclose them in []. Something like,
a = "ID =" & idwanted
b = "[Name] = '" & namewanted & "'"
Form_Form1.Form.Filter = a & " And " & b
Form_Form1.Form.FilterOn = True
I added check boxes to my MS Access form. Now I am trying to run a report based on those check boxes.
They are about 6 check boxes. How can I translate the check boxes from check marks to words?
An example of this would be on the form. Pizza toppings(onions,sausage,olives,cheese,chicken,mushrooms).
I need to be able to turn the check boxes from 6 individual check-boxes to make one toppings fields.
Also it is to late to change the table to use some form of list box.
Thank you.
Put a new text field into your report with a control source similar to the following:
=iif([onions],"Onions ", "") & iif([sausage],"Sausage ") & iif([olives],"Olives ","")
And so on...
If you would like to have commas in between the ingredients, you could also use something like the following:
=Concat(", ", iif([onions],"Onions", ""), iif([sausage],"Sausage"), iif([olives],"Olives ",""))
And put a Concat() function similar to this in one of your Modules:
Public Function Concat(Delimiter As String, ParamArray Strings()) As String
Dim s As Variant, ret As String
ret = ""
For Each s In Strings
If Not IsNull(s) And Not IsEmpty(s) And s <> "" Then
If ret = "" Then
ret = s
Else
ret = ret & Delimiter & s
End If
End If
Next
Concat = ret
End Function
You want something like this:
If chkTopping1 = True then MyTopping1 = "Bacon"
If chkTopping2 = True then MyTopping2 = "Sausage"
If chkTopping3 = True then MyTopping3 = "Pepperoni"
If chkTopping4 = True then MyTopping4 = "Mushrooms"
If chkTopping5 = True then MyTopping5 = "Meatballs"
If chkTopping6 = True then MyTopping6 = "Olives"
If Not IsNull(MyTopping1) then
AllToppings = MyTopping1 & ", "
If Not IsNull(MyTopping2) then
AllToppings = AllToppings & MyTopping2 & ", "
If Not IsNull(MyTopping3) then
AllToppings = AllToppings & MyTopping3 & ", "
If Not IsNull(MyTopping4) then
AllToppings = AllToppings & MyTopping4 & ", "
If Not IsNull(MyTopping5) then
AllToppings = AllToppings & MyTopping5 & ", "
If Not IsNull(MyTopping6) then
AllToppings = AllToppings & MyTopping6
AllToppings is now your text field. I'm positive there's a more graceful way to do this, but my brain is kinda burnt after a long day at the office.
I´m saving a date in a table like this:
Me!lastchangedate.Caption = Now
Set db = CurrentDb
Set rs = db.OpenRecordset("background", dbOpenTable)
rs.AddNew
rs![date] = Me!lastchangedate.Caption
rs.Update
rs.Close
Later I want to read this date out of the database and show it in a Label:
sqlstrdate = "SELECT date FROM background " _
& " WHERE SAP_ID = '" _
& Me!sapidtxt.Value & "'"
retvaldate = CurrentDb.OpenRecordset(sqlstrdate)
Until here it´s working but if I now try to show "retvaldate" as MsgBox or in a label I always get the error message: Error 13 type mismatch.
Im trying to use this to show the saved date in a label.
Me!lastchangedate.Caption = (retvaldate)
Is there an option to change the label type or do I have to change the "retvaldate" to a date type (which also gives me the same error).
You are trying to set 'retvaldate' like opening a recordset. The following should provide the correct result (BTW, why do you use reserved words like 'date' as a field name?)
Dim rs As Recordset
Dim sqlstrdate As String
sqlstrdate = "SELECT date FROM background " _
& " WHERE SAP_ID = '" _
& Me!sapidtxt.Value & "'"
Set rs = CurrentDb.OpenRecordset(sqlstrdate)
If Not rs.EOF Then
retvaldate = rs.Fields("Date")
Else
retvaldate = "No Records"
End If
rs.Close
Set rs = Nothing
'Then later... but I hope the variable is in scope (Global, form, subroutine)
Me!lastchangedate.Caption = retvaldate