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!

what autoexec do?

Status
Not open for further replies.

action8

Technical User
Nov 17, 2010
13
US
I would like to know
the following function
why do I need the path backend data?
I already linked front end with backend tables on
MS Access 2003
''''''''''''''''''''''''''''''
Public Function Autoexec()
On Error GoTo Autoexec_Err
DoCmd.RepaintObject
'SetStartupProperties

'**********Back End Database Set*********
gstrServer = Application.CurrentProject.Path & "\PMDB.mdb"
'****************************************

'GetNewContestID
'DoCmd.Close acForm, "frmOpeningPage"
'LastMonthSaved

'sBuildTimes
sGetTimes
'CurrentProject.StartUpShowDBWindow = True


DoCmd.OpenForm "frmMainForm"

Autoexec_Exit:
Exit Function

Autoexec_Err:
Application.Echo True
Select Case Err.Number
Case Else
Call GlobalErr("Autoexec", Err.Number)
Resume Autoexec_Exit
Resume
End Select
End Function
 
Oh Thanks
it is used as follows:
First it is Global string variable for a path.
right now, I don't have SQL just a MS Access 2003.
and this say sMainOpenSQL, this does not make sense!!
what does the whole thing do? please help.

Global gstrServer As String

Public Sub sMainOpenSQL(cnnDB As ADODB.Connection, strServer As String)
Set cnnDB = New ADODB.Connection

With cnnDB
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Open strServer, "admin", ""

End With

End Sub
????????????????????????????
Private Sub sGetTimes()
Dim rstApptTimes As ADODB.Recordset, strSQL As String, I As Integer

sMainOpenSQL cnnWHIHQ, gstrServer
Set rstApptTimes = New ADODB.Recordset

ReDim arrTimeRange(41)

strSQL = "SELECT ATTime FROM tblApptTimes ORDER BY ATID"
rstApptTimes.Open strSQL, cnnWHIHQ, adOpenForwardOnly
If Not rstApptTimes.EOF Then 'go with employee fill in combo
I = 1
While Not rstApptTimes.EOF
arrTimeRange(I) = Format(rstApptTimes("ATTime"), "h:mm AMPM")
I = I + 1
rstApptTimes.MoveNext
Wend
End If

End Sub
?????????????????????????????????
Private Sub sBuildTimes()
Dim I As Integer, strNewTime As String, strSQL As String

sMainOpenSQL cnnWHIHQ, gstrServer

cnnWHIHQ.Execute "DELETE FROM tblApptTimes"

ReDim arrTimeRange(41)
strNewTime = DateAdd("n", 15, "01/02/2009 07:45")
arrTimeRange(1) = Format(strNewTime, "h:mm AMPM")

strSQL = "INSERT INTO tblApptTimes(ATTime) VALUES('" & Format(arrTimeRange(1), "h:mm AMPM") & "')"
cnnWHIHQ.Execute strSQL

For I = 2 To 41
strNewTime = DateAdd("n", 15, strNewTime)
arrTimeRange(I) = Format(strNewTime, "h:mm AMPM")
strSQL = "INSERT INTO tblApptTimes(ATTime) VALUES('" & Format(arrTimeRange(I), "h:mm AMPM") & "')"
cnnWHIHQ.Execute strSQL
Next I

If Not (cnnWHIHQ Is Nothing) Then
If cnnWHIHQ.State <> adStateClosed Then
cnnWHIHQ.Close
End If
End If
Set cnnWHIHQ = Nothing

End Sub
 
I already have the table tblAppTimes
with 2 columns and 41 records.

table tblApptTimes
column1 column2
ATID ATTIME
1 8:00:00 AM
2 8:15:00 AM
3 8:30:00 AM
4 8:45:00 AM
5 9:00:00 AM
. ..........
. ..........
40 5:45:00 PM
41 6:00:00 PM

Please explain in English
what the five lines of code in sMainOpenSQL ?

Public Sub sMainOpenSQL(cnnDB As ADODB.Connection, strServer As String)
Set cnnDB = New ADODB.Connection

With cnnDB
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Open strServer, "admin", ""

End With
 
I don't know why the table is rebuilt. I don't know why the programmer is using ADO vs DAO. This is typical ADO code. You can search help on what each line is for.

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top