I am trying to compile my VBA code in Access 2010, however, I keep getting this error: Sub or Function not defined. When I click OK, it highlights the following code: - Me.txtFileLoc
-
-
'Full code line
-
If Me.txtFileLoc & "" <> "" And FileExists(Me.txtFileLoc) Then
I know that the spelling is correct because I used the inteliSense prompt to finish the typing for me. I tried renaming the control, same problem (after I renamed the control reference of course). I tried referencing it with the long reference through the form like this: - Forms("frmFileImport").Controls("txtFileLoc")
The error that I get then highlights the .Controls. Further up the form's code module, I have a reference to the same textbox and it doesn't have a problem with it. I discovered it because when I renamed the control and tried to compile the database, it then caught it. Once I fixed the name, it worked and then went back down to this same problem line. I have compacted and repaired the database. I have rebooted my computer. I tried removing my reference to the Microsoft Office xx.x Object Library that I had added and still nothing (I didn't think that it would, but I had to try). I don't know what else to do at this point. Any ideas?
9 6270
I think that I just fixed it, but I have no idea how it fixed it. I switched the order of the criteria in line #4 and it works now. So my code is now - If FileExists(Me.txtFileLoc) And Me.txtFileLoc & "" <> "" Then
Can anyone tell me why this made a difference?
NeoPa 32,556
Expert Mod 16PB
I can only imagine the issue is somewhere other than the code you've shown Seth. The compiler often gets confused when paired statements are not paired (Like Do / Loop, For / Next, If / End If, etc). It seems to report the issue as something further down the code.
If all you say is fully accurate then I cannot see why it would report it as you've said.
Here is the full procedure in its current state. The only thing that got changed was the If statement on line 7 (line 20 of the incode line numbers) - Private Sub cmdImport_Click()
-
10 On Error GoTo Error_Handler
-
-
Dim PF As TSC_PF_Simple
-
Dim strFilePath() As String
-
-
20 If FileExists(Me.txtFileLoc) And Me.txtFileLoc & "" <> "" Then
-
30 If Not IsNull(Me.cboScanDate) And Not IsNull(Me.cboBranch) Then
-
40 Set PF = New TSC_PF_Simple
-
-
50 PF.Title = "Importing Scan Results..."
-
60 PF.UpdateTask 0, "Preparing for Import"
-
70 PF.Show
-
-
80 DoCmd.SetWarnings False
-
90 DoCmd.RunSQL "DELETE FROM VulnerabilitiesImport"
-
100 DoCmd.SetWarnings True
-
-
110 strFilePath = Split(Me.txtFileLoc, "\")
-
-
120 PF.UpdateTask 0.05, "Importing File: " & strFilePath(UBound(strFilePath))
-
130 DoCmd.TransferText acImportDelim, , "VulnerabilitiesImport", Me.txtFileLoc, True
-
-
'Run the information setup Files
-
140 PF.UpdateTask 0.5, "Processing Risk Levels"
-
150 InsertRiskLevels
-
-
160 PF.UpdateTask 0.6, "Processing Hosts"
-
170 InsertHosts Me.cboBranch
-
-
180 PF.UpdateTask 0.7, "Processing Vulnerabilities"
-
190 InsertVulnerabilities
-
-
200 PF.UpdateTask 0.8, "Merging Data"
-
210 CopyVulnerabilities Me.cboScanDate
-
-
220 PF.Title = "Import Complete"
-
230 PF.UpdateTask 1, "Operation Successful"
-
-
240 Else
-
250 MsgBox "Please select a scan description and branch"
-
260 End If
-
270 Else
-
280 MsgBox "Either no file has been selected or the selected file does not exist. Please select an existing file."
-
290 End If
-
-
Exit_Procedure:
-
300 Set PF = Nothing
-
310 Exit Sub
-
-
Error_Handler:
-
320 If Err.Number = 3501 Then
-
330 MsgBox "The file you have selected is open. Please close it and then try importing it again."
-
340 Resume Exit_Procedure
-
350 End If
-
-
360 If TempVars("RunMode") = "Test" Then
-
370 Call ErrorMessage(Err.Number, Err.Description, "Form_frmFileImport: cmdImport_Click")
-
380 Else
-
390 TSCs_ReportUnexpectedError "cmdImport_Click", "Form_frmFileImport", "Custom info"
-
400 End If
-
410 Resume Exit_Procedure
-
420 Resume
-
-
-
End Sub
-
I think the lack of parenthesis in the complex IF / THEN has contributed to this problem. When in doubt, and especially when not in doubt, use ()
Jim
I didn't think of using parenthesis. That might explain why I had the issue. Unfortunately, I can't duplicate the error by just switching the order back to how it was since it doesn't produce the error any more. Maybe it just figured out what I was trying to do :)
NeoPa 32,556
Expert Mod 16PB
Although it can often make the code easier to read when parentheses (plural) are added, it's rarely necessary. This is because all operators have a level of precedence which usually ensures they are processed in the order you would expect.
Personally, I'd code it as : - With Me
-
If .txtFileLoc > "" Then
-
If FileExists(.txtFileLoc) Then
-
...
-
End If
-
End If
-
End With
But that's not because your way wouldn't be expected to work fine TBF.
I like NeoPa's way, it adds clarity at the cost of nothing.
Jim
For some reason I hate nesting IF statements. Two I'm okay with, but after that, I try to figure out another way. I guess that is why I do most of mine in a single IF statement when possible. However, I will take the recommendation of an expert over my self-taught practices any day. Thanks for all your help.
NeoPa 32,556
Expert Mod 16PB
Normally I'd use And and Or within a single statement but in this case one depends on the other, so it fits better to test one first then only even check the other if it's worth it. When using And and Or it's easier to read and maintain if parentheses are used.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Andrew Boothman |
last post by:
Hi,
This may be the dumbest question ever, but in the following code (using
PHP 4.3.8) how do I call b() from within a()?
class test {
function a() {
print "a called";
b();
|
by: lallous |
last post by:
Usually you can check for a defined variable as:
#ifdef DEF1
// do stuff here
#endif
Can I test if a function is defined then do things, example:
int myFnc()
{
// blah blah
}
|
by: rashmi |
last post by:
how to use static function defined in one file in another file is that
impposiible in 'c '
|
by: jeniffer |
last post by:
Can a static function defined in a C file be ever referred (called)
externally from another C file?If so in which conditions?
|
by: thisis |
last post by:
Hi All,
i have this.asp page:
<script type="text/vbscript">
Function myFunc(val1ok, val2ok)
' do something ok
myFunc = " return something ok"
End Function
</script>
|
by: silverburgh.meryl |
last post by:
Hi,
I have a function called 'test' defined in A.py.
How can I call that function test in my another file B.py?
Thank you.
|
by: yawnmoth |
last post by:
Say I have the following:
<script>
var cat = (function() {
var name = "";
function changeName(name) {
this.name = name;
}
|
by: thekingsnake |
last post by:
After following the instructions from the answer below:
http://bytes.com/topic/javascript/answers/153274-script-iframe-can-not-call-functions-defined-parent-document
I was able to have the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |