I want to hide or not show Field Names if value is Null, for fields "Location" and "Bin" when updating my eBay webpage Custom Label Fields.
Tried
If IsNull(Me!Location) Then
Me!Location.Visible = False
Else
Me!Location = True
but keep getting errors (Method or data not found or runtime 438) with the following code.
Call IE.Document.getElementById("editpane_skuNumber").setAttribute("value", ([CustomLabelCombine]) & " " & ("Location" & " " & [Location]) & " " & ("Bin" & " " & [Bin]))
If you have a better solution please let me know.
Is IE.Document.GetelementsbyID a subroutine or function? if not, remove the word "call" and replace with
me.Location = IE.Document.getElementById("editpane_skuNumber").setAttribute("value", ([CustomLabelCombine]) & " " & ("Location" & " " & [Location]) & " " & ("Bin" & " " & [Bin]))
If IsNull(Me!Location) Then
Me!Location.Visible = False
Else
Me!Location = True
End IF
Comment1:
When using "Call" you are asking the current procedure to "Call" a public subroutine. Example below
Private Sub Button1_Click()
Call TestRoutine
End Sub
Public Sub TestRoutine()
Msgbox "You clicked Button 1"
End Sub
If you aren't calling another subroutine to execute more coding, then remove the word "Call".
I also noticed your if is missing the .visible after the else for line
Me!Location = true
Should be:
Me!Location.Visible = true
Related
I created a public function, so that I could call it on Access forms, and display the result in a textbox control. This is the public function:
Public Function CurrRecs(xRecName As String, frmName As Form, tblCount As String)
If Forms(frmName).NewRecord Then
frmName.txtCurrRec = "New " & xRecName & " Record"
Else
frmName.txtCurrRec = CStr(frmName.CurrentRecord) & " of " & _
DCount("ID", tblCount) & " " & xRecName & "s"
End If
End Function
This is what I have on the Form_Current()
CurrRecs("RecordType", "frmCurrentForm", "tblGetCountFromHere")
I get a compile error: Expected:=
Anyone know what I'm doing wrong?
The error is because you're declaring frmName as a form, but using it as a string in one place, and a form in another
Also, if you want the table count, use Form.RecordSet.RecordCount, not an elaborate DCount
Rewritten:
Public Function CurrRecs(xRecName As String, frmName As String)
Dim frm As Form
Set frm = Forms(frmName)
If frm NewRecord Then
frm.txtCurrRec = "New " & xRecName & " Record"
Else
frm.txtCurrRec = CStr(frm.CurrentRecord) & " of " & _
frm.RecordSet.RecordCount & " " & xRecName & "s"
End If
End Function
I am trying to filter a subform with a combobox. What I have works, but it keeps bringing up an "Enter Parameter Value" textbox. When I enter the value I want to filter with, it searches the subform no problem. I would prefer to not have to enter the value though as it defeats the purpose of the combobox.
Here is my code for the ComboBox,
Private Sub ComboFE_AfterUpdate()
On Error GoTo Proc_Error
If IsNull(Me.ComboFE) Then
Me.SubFormPF.Form.Filter = ""
Me.SubFormPF.Form.FilterOn = False
Else
Me.SubFormPF.Form.Filter = "Lead_FE = " & Me.ComboFE
Me.SubFormPF.Form.FilterOn = True
End If
Proc_Exit:
Exit Sub
Proc_Error:
MsgBox "Error " & Err.Number & " in setting subform filter:" & vbCrLf & Err.Description
Resume Proc_Exit
End Sub
I have checked and made sure all the names are correct and match the corresponding items on my form.
Any Ideas?
Many Thanks
When applying a filter on a text column, the value needs quotes.
Me.SubFormPF.Form.Filter = "Lead_FE = '" & Me.ComboFE & "'"
To avoid problems if the value itself contains quotes, use Gustav's CSql() function from here: https://stackoverflow.com/a/36494189/3820271
Me.SubFormPF.Form.Filter = "Lead_FE = " & CSql(Me.ComboFE.Value)
This works for all data types.
Can anyone solve my issue
Form: SB_1 (this is a Customer Invoice creation form)
Form: Add_NewRelations (this is a Customer details adding form)
I have used a VBA code in Form: SB_1 on a cmd (Button) for Data passing from one form to another form of Add_NewRelations for New Customer details are needed to update.
So that VBA working is good as per Code Tag. But some of exist customer details are no need to update into Form: Add_NewRelations. So in this case i have added IF Statement with DCount in the VBA code.
When i added If statement with DCount then whole VBA is didn't working... i think DCount is wrong... how can i correction it??
Can anyone please replay how to solve this problem??
Private Sub Button_Click()
On Error GoTo ErrorHandler
'Me.Refresh
Dim strCriteria As String
strCriteria = "CIDCustomer = '" & Trim(Trim(Me!RID) & " " & Trim(Me!RName)) & "'"
'If DCount("*", "CIDCustomer", "RelationsQry") > 0 Then
'Cancel = True
'Else
If DCount("*", "RelationsQry", strCriteria) > 0 Then
Cancel = True
Else
'If Not IsNull([Customer]) Then
'Me.Visible = False
DoCmd.OpenForm "Add_NewRelations", acNormal, , , , acWindowNormal
Forms![Add_NewRelations].Form.RID = Me.CID2
Forms![Add_NewRelations].Form.RName = Me.Customer
Forms![Add_NewRelations].Form.RType.Value = "Customer"
Forms![Add_NewRelations].Form.Address = Me.Address
Forms![Add_NewRelations].Form.TINNumber = Me.TINNumber
Forms![Add_NewRelations].Form.TownVLG = Me.TownVLG
Forms![Add_NewRelations].Form.RName.SetFocus
'Forms![Add_NewRelations].Visible = False
'DoCmd.Close
End If
ErrorHandler:
End Sub
To pass the quotes into the SQL you need to escape them, and you need additional single quotes as well for the elements of the criteria.
Instead of:
strCriteria = "CIDCustomer = '" & Trim(Trim(Me!RID) & " " & Trim(Me!RName)) & "'"
try
strCriteria = "" "CIDCustomer = '" & Trim(Trim(Me!RID) & "' & " " & '" Trim(Me!RName)) & "'" ""
I've created a form in Access where I have a series of required fields. Once all of the required fields have been completed and the user clicks a button called Add New Record, I need the form to refresh so they can enter new data. I've created this form by using snipits I've found on Stackoverflow. For the most part the form does what I need it to do. (It checks for missing fields, displays error is fields are correct) The piece I'm missing is is won't refresh the page. It's not displaying any errors. Any insight or suggestions would be appreciated. Below is the code I'm currently using.
Thank you
Private Function CheckAllFields() As Boolean
Dim Ctrl As Control
CheckAllFields = False
For Each Ctrl In Me.Controls
If Ctrl.Tag = "*" And IsNull(Ctrl) Then
MsgBox "Please complete ALL required fields"
CheckAllFields = True
Exit For
End If
Next Ctrl
End Function
Private Sub New_Record_Click()
If CheckAllFields = True Then Exit Sub
If PYMT_AMT < AMT_RECOVERED And CONSOLIDATED_CK = "NO" Then
MsgBox "CONSOLIDATED CHECK ERROR" & vbCrLf & _
"The Amount Recovered is greater than the Exception Amount." & vbCrLf & _
" Please confirm answer to Consolidated Check question"
End If
If PYMT_AMT > AMT_RECOVERED And CONSOLIDATED_CK = "YES" Then
MsgBox "CONSOLIDATED CHECK ERROR" & vbCrLf & _
"The Amount Recovered is less than the Exception Amount." & vbCrLf & _
" Please confirm answer to Consolidated Check question"
End If
If PYMT_AMT > AMT_RECOVERED And PARTIAL_RECOVERY = "NO" Then
MsgBox "PARTIAL RECOVERY ERROR" & vbCrLf & _
"The Amount Recovered is less than the Exception Amount." & vbCrLf & _
" Please confirm answer to Partial Recovery question."
End If
If PYMT_AMT < AMT_RECOVERED And PARTIAL_RECOVERY = "YES" Then
MsgBox "PARTIAL RECOVERY ERROR" & vbCrLf & _
"The Amount Recovered is greater than the Exception Amount." & vbCrLf & _
" Please confirm answer to Partial Recovery question."
End If
If RECOVERY_TYP = "Check Payable to Fiserv" And CHECK_NUM = "" Then
MsgBox "Please enter check number." & vbCrLf & _
" AND Please confirm answer to Partial Recovery question."
End If
If Me.RECOVERY_TYP = "Check Payable to Fiserv" Then
If IsNull(Me.CHECK_NUM) Then
MsgBox "Please Enter Check Number"
Cancel = True
Me.CHECK_NUM.SetFocus
End If
End If
End Sub
Seems like you could just add:
Me.DataEntry =True
...before your "End Sub".
I am not sure if your form is bound to a table, but if so, once you have ensured that the existing form data was validated and persisted, could you not just add the below line to your code? This should bring you to a new table record with the form fields empty.
DoCmd.GoToRecord acDataForm, "Your Form Name", acNewRec
I have a data entry form (Access 2007) which is designed to find out if the captured animal already has an existing WHno. Unfortunately, the data is messy and these is not a single unique identifier so several tests must be performed to narrow the search.
The animal could have 1 to 10 different pieces of information which will help identify the animal’s existence in the database. (The script only tests for about half of them thus far) I was thinking the best way to do this would to be to “build” a DCount and/or SQL statement based on which fields the user selects. I hope test to see if a particular text field box (unbound) has been filled out, and if yes, concatenate that section of code to the DCount/SQL statement, then move on to the next text field box to test.
Once the statement has been completely built, I want to test to see how many records have been counted/selected. If one record has been selected, I want to display the results in FormA. If 2 or more records are found, I want to display the records in a multi-listing form (FormB) from which the user can select the correct animal based on additional information not tested but displayed in FormB. If zero records are found, I want to create a new record with the data entered into the form updated into the table.
The hurdle I am struggling with now is building the DCount statements. I keep getting syntax errors . I do not know how to put this together piecemeal when the function bombs out because the syntax is incomplete (which it will be until I finish “building” it.)
I know the data is a mess. The scene out in the field is chaotic, different people gather different kinds of information, and not all the data that should be entered on the paper forms get filled out completely - if at all. The data gathering procedures are unlikely to change anytime soon.
Ideas? A different but easier approach idea is also welcome. New to this and not sure of all my programming options.
Also, how long can this statement be before it bombs out?
Code so far:
Private Sub GenerateWHno_Click()
Dim rs As DAO.Recordset
If IsNull(Forms!F_HotelEntry!txtSpecies) Or (Forms!F_HotelEntry!txtSpecies) = "" Then
MsgBox "Species is a required field. Please enter a species"
Exit Sub
End If
MsgBox txtSpecies
' Each line of code below indicates a data entry field(s) that needs testing and appended to SpeciesCount if "true". The first line is unchanging and is declared upfront.
'SpeciesCount = DCount("[Species]", "AnimalInfo", "(nz([Status])= '' OR [Status] = 'Alive' OR [Status] = 'Unknown') AND ([Species]= '" & txtSpecies & "')" _
' & "AND (((nz([L_ET_Color1])= '" & Nz(txtL_ET_Color1) & "' AND nz([L_ET_No1])= '" & nz(txtL_ET_No1) & "')" _
' & "AND (((nz([R_ET_Color1])= '" & Nz(txtR_ET_Color1) & "' AND nz([R_ET_No1])= '" & nz(txtR_ET_No1) & "')" _
' & "AND nz([L_ET_No2])= '" & nz(txtL_ET_No2) & "')" _
' & "AND nz([R_ET_No2])= '" & nz(txtR_ET_No2) & "')" _
' & "")
'If txtL_ET_Color Is Not Null Or txtL_ET_No Is Not Null Then
'LET1 = & "AND (((nz([L_ET_Color1])= '" & Nz(txtL_ET_Color1) & "' AND nz([L_ET_No1])= '" & nz(txtL_ET_No1) & "')" _
'Species Count = SpeciesCount & LET1
'End If
'If txtR_ET_Color Is Not Null Or txtR_ET_No Is Not Null Then
'RET1 = & "AND (((nz([R_ET_Color1])= '" & Nz(txtR_ET_Color1) & "' AND nz([R_ET_No1])= '" & nz(txtR_ET_No1) & "')" _
'Species Count = SpeciesCount & RET1
'End If
'If txtL_ET_No2 Is Not Null Then
'LET2 = AND nz([L_ET_No2])= '" & nz(txtL_ET_No2) & "')" _
'Species Count = SpeciesCount & LET2
'End If
'If txtR_ET_No2 Is Not Null Then
'RET2 = AND nz([R_ET_No2])= '" & nz(txtR_ET_No2) & "')" _
'Species Count = SpeciesCount & RET2
'End If
'There are about 4 more options/fields to add to the script but you get the idea.
'Thus: If user selected Species, and filled out L_ET_Color1 and/or L_ET_No1, the final concatenation (DCount statement)would look like this:
SpeciesCount = DCount("[Species]", "AnimalInfo", "([Status]= 'Alive' OR [Status] = 'Unknown' OR nz([Status]) = '') AND [Species]= '" & txtSpecies & "' AND (nz([L_ET_Color1])= '" & Nz(txtL_ET_Color1) & "' AND nz([L_ET_No1])= '" & Nz(txtL_ET_No1) & "')")
If SpeciesCount > 1 Then
MsgBox SpeciesCount & " Greater than 1. Please select correct animal"
'Create SQL statement that mimics DCount statement and display all fields from AnimalInfo table as multilisting to select from
ElseIf SpeciesCount = 0 Then
MsgBox "You need a new WHno"
WHno = Nz(DMax("WHno", "AnimalInfo")) + 1
MsgBox WHno
Set rs = CurrentDb.OpenRecordset("AnimalInfo")
rs.AddNew
rs!WHno = WHno
rs!Species = txtSpecies
rs!L_ET_Color1 = txtL_ET_Color1
rs!L_ET_No1 = txtL_ET_No1
rs.Update
rs.Close
Else
'Create SQL statement that mimics DCount statement and display all fields from AnimalInfo table as single listing in a form.
MsgBox "You're WHno is " & WHno & " Is this the correct WHno?"
End If
Forms!F_HotelEntry!txtSpecies = ""
Forms!F_HotelEntry!txtL_ET_Color1 = ""
Forms!F_HotelEntry!txtL_ET_No1 = ""
End Sub
I would suggest to first compose the condition into a string variable. There you can print its content via Debug.Print and see what the problem might be.
If you cannot spot the problem via inspection alone, paste the generated string to the Sql view of a proper query and see if Access gives you helpful information on switching to design view.