Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA error 1

Status
Not open for further replies.

ceil32

MIS
Apr 8, 2008
263
0
0
IE
Hi,

I have a working program on a Windows XP Client.

Both programs run from C:\Comtec\Comtec_country.exe

When I run the program on the Windows 7 client, I get the following VB error (in bold below) - I've pasted the whole program code

Can anyone assist? Thanks

-------------

Option Compare Database

Private Sub Command13_Click()
Numberboxes = InputBox("How many boxes do you want to label")
Weight = InputBox("What's the Gross Weight of the Shipment")
address2 = FindReplace(address, Chr(13) & Chr(10), "#@#")
If addinfo = "" Then addinfo = "-"
commandStr = "C:\comtec\comtec_country.exe " & Chr(34) & Numberboxes & "||" & Weight & "||" & address2 & "||" & addinfo & "||" & Now() & Chr(34)
'MsgBox (commandStr)
Shell (commandStr)
Rem haha


End Sub

Private Sub First_Click()
On Error GoTo Err_First_Click


DoCmd.GoToRecord , , acFirst

Exit_First_Click:
Exit Sub

Err_First_Click:
MsgBox Err.Description
Resume Exit_First_Click

End Sub
Private Sub prev_Click()
On Error GoTo Err_prev_Click


DoCmd.GoToRecord , , acPrevious

Exit_prev_Click:
Exit Sub

Err_prev_Click:
MsgBox Err.Description
Resume Exit_prev_Click

End Sub
Private Sub Command9_Click()
On Error GoTo Err_Command9_Click


DoCmd.GoToRecord , , acNext

Exit_Command9_Click:
Exit Sub

Err_Command9_Click:
MsgBox Err.Description
Resume Exit_Command9_Click

End Sub
Private Sub Last_Click()
On Error GoTo Err_Last_Click


DoCmd.GoToRecord , , acLast

Exit_Last_Click:
Exit Sub

Err_Last_Click:
MsgBox Err.Description
Resume Exit_Last_Click

End Sub
Private Sub new_Click()
On Error GoTo Err_new_Click


DoCmd.GoToRecord , , acNewRec

Exit_new_Click:
Exit Sub

Err_new_Click:
MsgBox Err.Description
Resume Exit_new_Click

End Sub
Function FindReplace(strOrig As Variant, strOld As String, strNew As String)
'Function to search and replace characters in a string
'-----------------------------------------------------------
' ARGUEMENT DESCRIPTION
' --------------------------------------------------------
' strOrig String in which to
' search/replace.
'
' strOld String you are searching for.
'
' strNew String to replace the searched
' for string.
' --------------------------------------------------------
' EXAMPLE
' --------------------------------------------------------
' MyString = "555.318.6755"
' MyNewString = FindReplace(MyString,".","-")
' (MyNewString is now "555-318-6755")
'-----------------------------------------------------------

Dim intAt As Integer, strAltered As String

'Check for arguements
If IsNull(strOld) Or IsNull(strNew) Then
FindReplace = "ERROR! CHECK ARGUEMENTS!"
Exit Function
End If

'Check for null string
If IsNull(strOrig) Then
FindReplace = Null
Exit Function
End If

'Do function
For intAt = 1 To Len(strOrig)
If Mid(strOrig, intAt, Len(strOld)) = strOld Then
strAltered = strAltered & strNew
intAt = intAt + (Len(strOld) - 1)
Else
strAltered = strAltered & Mid(strOrig, intAt, 1)
End If
Next intAt
FindReplace = strAltered

End Function
 
Which error on which line ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
It would also be helpful if you used TGML tags for CODE and other formatting. Your posting is very difficult to read without copying and pasting into a separate editor.

Duane
Hook'D on Access
MS Access MVP
 
My apologies, the error occurs on this line:

'MsgBox (commandStr)

Option Compare Database

Private Sub Command13_Click()
Numberboxes = InputBox("How many boxes do you want to label")
Weight = InputBox("What's the Gross Weight of the Shipment")
address2 = FindReplace(address, Chr(13) & Chr(10), "#@#")
If addinfo = "" Then addinfo = "-"
commandStr = "C:\comtec\comtec_country.exe " & Chr(34) & Numberboxes & "||" & Weight & "||" & address2 & "||" & addinfo & "||" & Now() & Chr(34)
'MsgBox (commandStr)
Shell (commandStr)
Rem haha


End Sub

Private Sub First_Click()
On Error GoTo Err_First_Click


DoCmd.GoToRecord , , acFirst

Exit_First_Click:
Exit Sub

Err_First_Click:
MsgBox Err.Description
Resume Exit_First_Click

End Sub
Private Sub prev_Click()
On Error GoTo Err_prev_Click


DoCmd.GoToRecord , , acPrevious

Exit_prev_Click:
Exit Sub

Err_prev_Click:
MsgBox Err.Description
Resume Exit_prev_Click

End Sub
Private Sub Command9_Click()
On Error GoTo Err_Command9_Click


DoCmd.GoToRecord , , acNext

Exit_Command9_Click:
Exit Sub

Err_Command9_Click:
MsgBox Err.Description
Resume Exit_Command9_Click

End Sub
Private Sub Last_Click()
On Error GoTo Err_Last_Click


DoCmd.GoToRecord , , acLast

Exit_Last_Click:
Exit Sub

Err_Last_Click:
MsgBox Err.Description
Resume Exit_Last_Click

End Sub
Private Sub new_Click()
On Error GoTo Err_new_Click


DoCmd.GoToRecord , , acNewRec

Exit_new_Click:
Exit Sub

Err_new_Click:
MsgBox Err.Description
Resume Exit_new_Click

End Sub
Function FindReplace(strOrig As Variant, strOld As String, strNew As String)
'Function to search and replace characters in a string
'-----------------------------------------------------------
' ARGUEMENT DESCRIPTION
' --------------------------------------------------------
' strOrig String in which to
' search/replace.
'
' strOld String you are searching for.
'
' strNew String to replace the searched
' for string.
' --------------------------------------------------------
' EXAMPLE
' --------------------------------------------------------
' MyString = "555.318.6755"
' MyNewString = FindReplace(MyString,".","-")
' (MyNewString is now "555-318-6755")
'-----------------------------------------------------------

Dim intAt As Integer, strAltered As String

'Check for arguements
If IsNull(strOld) Or IsNull(strNew) Then
FindReplace = "ERROR! CHECK ARGUEMENTS!"
Exit Function
End If

'Check for null string
If IsNull(strOrig) Then
FindReplace = Null
Exit Function
End If

'Do function
For intAt = 1 To Len(strOrig)
If Mid(strOrig, intAt, Len(strOld)) = strOld Then
strAltered = strAltered & strNew
intAt = intAt + (Len(strOld) - 1)
Else
strAltered = strAltered & Mid(strOrig, intAt, 1)
End If
Next intAt
FindReplace = strAltered

End Function
 
At the top of your module add

Option Compare Database
Option Explicit

Then hit debug compile. Should help answer your question.
 
Thanks I'll try that in the morning and let you know.
 
Again, WHICH error ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
When I add in the second line below and hit debug compile:

Option Compare Database
Option Explicit

--

The First line below comes up in yellow:

Private Sub Command13_Click()
Numberboxes = InputBox("How many boxes do you want to label")
Weight = InputBox("What's the Gross Weight of the Shipment")
address2 = FindReplace(address, Chr(13) & Chr(10), "#@#")
If addinfo = "" Then addinfo = "-"
commandStr = "C:\comtec\comtec_country.exe " & Chr(34) & Numberboxes & "||" & Weight & "||" & address2 & "||" & addinfo & "||" & Now() & Chr(34)
'MsgBox (commandStr)
Shell (commandStr)
Rem haha


End Sub
--

I also get the on screen error:

Compile error: Variable not defined
 
Compile error: Variable not defined
Option Explicit forces you to Dim ALL variables used in the module.

BTW, you still didn't reply my question about the original error message ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I don't know how to replicate the original error message to answer your question.

 
I don't know how to replicate the original error message
Simply comment out the Option Explicit line and rerun your procedure.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
When I remove that line, the error is:

Run-time error '5':
Invalid procedure call or argument
 
What is the value of commandStr when the error raises ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
commandStr = "C:\comtec\comtec_country.exe "

The path exists
 
Doesn't comtec_country.exe expects some parameters ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Doesn't comtec_country.exe expects some parameters ?

It changes each time:

An Access pop up box asks me how many boxes to label - I enter a value of '1' & press 'Ok'
Whats the gross weight of the shipment - I enter 1


Then I get the above error from last post
 
Again, what is the value of commandStr when the error raises ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Again, what is the value of commandStr when the error raises ?

The value in the code is the line below - should I look elsewhere?

commandStr = "C:\comtec\comtec_country.exe
 
When the error raises hit the Debug button and then place the mouse pointer inside the word commandStr in your code to discover their actual value, or type ? commandStr in the immediate window (^G).

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for the patience:

Value = C:\Comtec\Comtec_country.exe "2||10KG||Company name#@Street#@post code Town#@#Country||-||07/05/2014 11.16:21"

The above is a record from the access Database that I want to print
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top