Database Next Record Question
Posted: Sat Feb 08, 2003 4:21 am
Restored from previous forum. Originally posted by Blair.
I have wrote a small bit of code to open a microsoft access database. The database containing 32 records and each record has 4 categories. I understand that the command "Result = NextDatabaseRow()" moves to the next record but how can I get the sample code to loop through each record using a button. Right now all it does is show the first record. Wht I would like to do is loop until the EOF with a button.
Any help would be appreciated
Blair
I have wrote a small bit of code to open a microsoft access database. The database containing 32 records and each record has 4 categories. I understand that the command "Result = NextDatabaseRow()" moves to the next record but how can I get the sample code to loop through each record using a button. Right now all it does is show the first record. Wht I would like to do is loop until the EOF with a button.
Any help would be appreciated
Blair
Code: Select all
XIncludeFile "Database_Constants.pb"
XIncludeFile "Database_windows.pb"
If Window_frmData()
Repeat
EventID=WaitWindowEvent()
Select EventID
Case #PB_EventGadget
Select EventGadgetID()
Case #Gadget_frmData_btnOK
If InitDatabase() = 0
MessageRequester("Error","Can not find Database Drivers",0)
EndIf
; Open the Labour Database
User$ = ""
Password$ = ""
#Database = 1
Result = OpenDatabase(#database,"Labour Rates",User$,Password$)
If Result = 0
MessageRequester("Error","Database Failed to Open",0)
EndIf
; Run the SQL query
Browse$ = "Select * from Labour"
Result = DatabaseQuery(Browse$)
If Result = 0
MessageRequester("Error","Query Failed",0)
EndIf
TotalNumber = window_frmData_strCount
Result = NextDatabaseRow()
Text1$ = GetDatabaseString(0)
Text2$ = GetDatabaseString(1)
Text3$ = GetDatabaseString(2)
Text4$ = GetDatabaseString(3)
SetGadgetText(#Gadget_frmData_strCode, Text1$)
SetGadgetText(#Gadget_frmData_strBud, Text2$)
SetGadgetText(#Gadget_frmData_strFor, Text3$)
SetGadgetText(#Gadget_frmData_strDescription, Text4$)
EndSelect
EndSelect
Until EventID=#PB_Event_CloseWindow And EventWindowID()=#Window_frmData
CloseWindow(#Window_frmData)
EndIf