Pass Field Value and Loop (Urgent Help Need)

T

Tim

Hi everyone,

I need some help for my following code. I want to pass
the field value of Receiver to strcmd. Then, I want to
loop Call Shell(strcmd, 1) for all records in my recordset.

Any help will be appreciated.

Thanks in advance.

Tim.


Code:

Public Sub Recordset()

Dim dbCurrent As Database
Dim rst As Recordset

Dim strReceiver As String

Dim strProgram As String
Dim strcmd As String


strReceiver = "Receiver" 'Field Name

strProgram = "c:\winnt\test.exe"

Set dbCurrent = DBEngine(0).Databases(0)
Set rst = dbCurrent.OpenRecordset("Select " & strReceiver
& " from Mail")

strcmd = strProgram & " " & strReceiver

Call Shell(strcmd, 1)

End Sub
 
E

Emilia Maxim

Tim said:
I need some help for my following code. I want to pass
the field value of Receiver to strcmd. Then, I want to
loop Call Shell(strcmd, 1) for all records in my recordset.

Tim,

If I understand correctly, you would want to have this:

Public Sub Recordset()

Dim dbCurrent As DAO.Database
Dim rst As DAO.Recordset
Dim strReceiver As String
Dim strProgram As String
Dim strcmd As String

strReceiver = "Receiver" 'Field Name
strProgram = "c:\winnt\test.exe"

Set dbCurrent = CurrentDB)
Set rst = dbCurrent.OpenRecordset("Select " & strReceiver & " from
Mail")

'Check if the Recordset is not empty,
'then proceed
If Not rst.BOF And Not rst.EOF Then
'Go to the first record
rst.MoveFirst

'Process each record until you reach
'the End Of File (=end of recordset)
Do Until rst.EOF
'Concatenate the value of the table field
'whose name is stored in strReceiver
strcmd = strProgram & " " & rst(strReceiver)

'Now, execute the program
Call Shell(strcmd, 1)
'Go to the next record
rst.MoveNext
Loop '...and do it all over again
End If

'Clean up before leaving
rst.Close
Set rst = Nothing
Set dbCurrent = Nothing

End Sub

Best regards
Emilia

Emilia Maxim
PC-SoftwareService, Stuttgart
http://www.maxim-software-service.de
 
T

Tim

Emilia,

Thanks.

Tim.
-----Original Message-----
recordset.

Tim,

If I understand correctly, you would want to have this:

Public Sub Recordset()

Dim dbCurrent As DAO.Database
Dim rst As DAO.Recordset
Dim strReceiver As String
Dim strProgram As String
Dim strcmd As String

strReceiver = "Receiver" 'Field Name
strProgram = "c:\winnt\test.exe"

Set dbCurrent = CurrentDB)
Set rst = dbCurrent.OpenRecordset("Select " & strReceiver & " from
Mail")

'Check if the Recordset is not empty,
'then proceed
If Not rst.BOF And Not rst.EOF Then
'Go to the first record
rst.MoveFirst

'Process each record until you reach
'the End Of File (=end of recordset)
Do Until rst.EOF
'Concatenate the value of the table field
'whose name is stored in strReceiver
strcmd = strProgram & " " & rst(strReceiver)

'Now, execute the program
Call Shell(strcmd, 1)
'Go to the next record
rst.MoveNext
Loop '...and do it all over again
End If

'Clean up before leaving
rst.Close
Set rst = Nothing
Set dbCurrent = Nothing

End Sub

Best regards
Emilia

Emilia Maxim
PC-SoftwareService, Stuttgart
http://www.maxim-software-service.de
.
 
T

Tim

Jen,

Thanks.

Tim.
-----Original Message-----
Hi,

Dim rst as DAO.Recordset ' have to specify DAO

Set rst = dbCurrent.OpenRecordset("Select " & strReceiver
& " from Mail")

Do While Not rst.EOF
strcmd = rs.Fields("Receiver").value
Call Shell(....)
Loop

This should get you on the right track.

Jen

.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top